使用idea创建SSM项目时数据源配置异常

异常:org.springframework.jdbc.CannotGetJdbcConnectionException

  jdbc.properties关于DB的配置(数据库名是liaody):



driverClassName=com.mysql.jdbc.Driver
password=root
username=root
url=jdbc:mysql://localhost:3306/liaody?characterEncoding=UTF8
 applicationContext.xml关于datasource的配置:
 <!-- 配置dataSource -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName">
            <value>${driverClassName}</value>
        </property>
        <property name="username">
            <value>${username}</value>
        </property>
        <property name="password">
            <value>${password}</value>
        </property>
        <property name="url">
            <value>${url}</value>
        </property>
    </bean>
启动Tomcat,访问DB,抛出异常:
 1 严重: Servlet.service() for servlet [springmvc] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
 2 ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘Administrator‘@‘localhost‘ (using password: YES))
 3 ### The error may exist in UserInfo-mapper.xml
 4 ### The error may involve com.springmvc.service.UserInfoService.getUser
 5 ### The error occurred while executing a query
 6 ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘Administrator‘@‘localhost‘ (using password: YES))] with root cause
 7 java.sql.SQLException: Access denied for user ‘Administrator‘@‘localhost‘ (using password: YES)
 8     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
 9     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
10     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
11     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
12     at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
13     at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
14     at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
15     at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2535)
16     at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2320)
17     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
18     at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
19     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
20     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
21     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
22     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
23     at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
24     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
25     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
26     at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
27     at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
28     at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
29     at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
30     at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
31     at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
32     at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
33     at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)
34     at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
35     at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)
36     at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:72)
37     at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:59)
38     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
39     at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
40     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
41     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
42     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
43     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
44     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
45     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
46     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
47     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
48     at java.lang.reflect.Method.invoke(Method.java:498)
49     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
50     at com.sun.proxy.$Proxy35.selectOne(Unknown Source)
51     at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
52     at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
53     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
54     at com.sun.proxy.$Proxy36.getUser(Unknown Source)
55     at com.springmvc.controller.LoginAndRegistController.loginExec(LoginAndRegistController.java:38)
56     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
57     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
58     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
59     at java.lang.reflect.Method.invoke(Method.java:498)
60     at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
61     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
62     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
63     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
64     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
65     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
66     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
67     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
68     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
69     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
70     at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
71     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
72     at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
73     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
74     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
75     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
76     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
77     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
78     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
79     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
80     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
81     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
82     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
83     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
84     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
85     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
86     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
87     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
88     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
89     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
90     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
91     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
92     at java.lang.Thread.run(Thread.java:745)
 

  异常的解决:jdbc.properties中关于DB的配置部分,加上jdbc.:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.password=root
jdbc.username=root
jdbc.url=jdbc:mysql://localhost:3306/liaody?characterEncoding=UTF8

        修改applicationContext.xml:

  <!-- 配置dataSource -->
    <bean    id="dataSource"     class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName">
            <value>${jdbc.driverClassName}</value>
        </property>
        <property name="username">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
        <property name="url">
            <value>${jdbc.url}</value>
        </property>
    </bean>

  异常原因:数据源配置错误。参考Spring官方文档的数据源配置后解决。

  虽然解决了该错误,但仍然有一个疑问,异常时试图登录DB的用户名是Administrator而不是root,这一点百思不得其解。有哪位大神知道什么回事么。

   
时间: 2024-10-22 12:01:21

使用idea创建SSM项目时数据源配置异常的相关文章

使用idea创建springMVC项目时如何配置tomcat

前段时间刚学到springMVC的时候连项目都不会创建,教程又是eclipse版的,这里记录一下,防止忘记. 首先创建一个spring项目,把spring MVC勾选上 下一步输入项目名后直接finish,它会自动给下载所需的包 内容就先不写了,直接配置tomcat 接下来把项目加进去,注意这里下面的Application context可以只保留一个 / ,它默认是会给你添加一长串的东西的 ,这里影响的是tomcat服务的启动地址 比如如果是只保留/的话地址就是http://localhost

【IDEA】创建maven项目时,报错[FATAL_ERROR] Cannot start Maven: Cannot find JRE &#39;1.7&#39;

在使用IDEA使用maven创建springMVC项目时,出现下面的错误,导致无法创建生成正常的springMVC项目结构,而只有一个pom文件: [FATAL_ERROR] Cannot start Maven: Cannot find JRE '1.7' 原因是:我在默认的setting配置里,File-->Other Setting-->Default Setting对应的maven配置里,设置了runner的VM参数:-DarchetypeCatalog=internal,这里需要用到

解决: Intelij IDEA 创建WEB项目时没有Servlet的jar包

今天创建SpringMVC项目时 用到HttpServletRequest时, 发现项目中根本没有Servlet这个包, 在网上搜了一下,这个问题是因为web项目没有添加服务器导致的. 配置tomecat 服务器 接着: 现在问题已经解决.. IDEA虽然使用的还不熟练,但大家要慢慢习惯哦,工作中这个IDE用的还是很普遍的.加油小伙伴们! 原文地址:https://www.cnblogs.com/ifeil/p/9378921.html

idea 为模块添加Tomcat依赖 解决: Intelij IDEA 创建WEB项目时没有Servlet的jar包

今天创建SpringMVC项目时 用到HttpServletRequest时, 发现项目中根本没有Servlet这个包, 在网上搜了一下,这个问题是因为web项目没有添加服务器导致的. 配置tomecat 服务器 添加选择tomcat之后,该项目就会默认添加tomcat中的jar依赖 原文地址:https://www.cnblogs.com/zhaoyanhaoBlog/p/10958312.html

创建Android项目时出错——No resource found that matches the given name &#39;Theme.AppCompat.Light&#39;

创建Android项目时出错,error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. 问题描述: 创建一个Android应用项目时,需指定其适用的SDK版本,默认如下图: 最低适用版本为:API 8: Android 2.2 (Froyo) 目标版本为:API 21: Android 4.X (L Preview) 编译版本为:A

创建android项目时,出现No resource found that matches the given name &#39;Theme.AppCompat.Light&#39;

这个错误会出现res文件夹有一个红色的叉叉 解决方法:  我们把我们创建的最低版本,改成android 4.0 这个问题就解决了 创建android项目时,出现No resource found that matches the given name 'Theme.AppCompat.Light'

创建Maven项目时,出现系列的错误提示的修改方法

1.创建Maven项目成功之后,需要修改一些配置, (1).java版本改为“本系统中java的版本号” 问题一:(2).Dynamic Web Module的version要改为2.5以上,然而本人出现的问题就是,当改为2.5以上之后出错,提示修改错误: 修改的方法见此文档:http://jingyan.baidu.com/article/fb48e8be3279766e622e1496.html [需要修改一些文档:windows->show view->选择Navigator: 之后就是

eclipse创建maven项目时如何修改web的版本和jdk的版本

在使用eclipse创建maven项目的时候,默认的web.xml的版本时2.3,默认jre的版本时1.5,有时候我们需要修改一些高的版本 1.首先找到项目下面的.settings下面的org.eclipse.wst.common.project.facet.core.xml文件 2.修改里面的文件为我们需要的jdk和web的版本 3.在我们的maven项目的pom文件里面添加编译插件 <build> <finalName>SSM</finalName> <plu

关于Eclipse创建Android项目时,会多出一个appcompat_v7的问题

问题描述: 使用eclipse创建一个Android项目时,发现project列表中会多创建出一个appcompat_v7项目,再创建一个Android项目时,又会再多出一个appcompat_v7_2,如果再次创建,会以此类推地创建出appcompat_v7_x格式的“多余项目”出来(此情况在ADT升级为22.6.x版本后出现,22.3.x前的版本不会有) 查明原因: ADT在22.3.x版本前没有出现该情况,升级为22.6.x版本后,才出现该情况,可以猜测是新版本导致.猜测到原因后可以分析下