在我的基于Spring + hibernate的Web应用程序中,我最近从tomcat-dbcp迁移到了tomcat-jdbc连接池。 之后我面临连接问题。 这是我的设置:
JNDI.xml:
<entry key="datasource">
<bean class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close" singleton="false">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://localhost:1433;DatabaseName=TESTDB"></property>
<property name="username" value="testuser"></property>
<property name="password" value="testpwd"></property>
</bean>
</entry>
上面的数据源早于tomcat-dbcp。
的applicationContext.xml:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="dataSource" />
</bean>
获取数据源属性的代码:
org.apache.tomcat.jdbc.pool.DataSource basicDataSource = (org.apache.tomcat.jdbc.pool.DataSource) context.lookup("datasource");
String password = basicDataSource.getPassword();
log.debug("jndi data source pwd::"+password);
当我尝试在eclipse中以调试模式查看密码时 - 显示为
Password not available as DataSource/JMX operation.
在应用程序启动时,它会尝试使用此信息登录数据库并获取一些详细信息。此时我在日志中看到以下错误:
12142 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
13269 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 18456, SQLState: S0001
13269 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Login failed for user 'testuser'.
13269 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'testuser'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2529)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4874)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:267)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:176)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:655)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:597)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:460)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:130)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:112)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:99)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:123)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:540)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:161)
at org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:51)
SQL Server日志说:
2014-05-16 16:53:16.44 Logon Error: 18456, Severity: 14, State: 8.
2014-05-16 16:53:16.44 Logon Login failed for user 'testuser'. Reason: Password did not match that for the login provided. [CLIENT: 10.1.10.21]
当我使用tomcat-dbcp时,一切运行良好。用户标识和密码有效,我可以使用这些凭据连接到数据库。这个问题似乎是一个tomcat-jdbc触发的问题。
我错过了任何配置吗? 我不确定这里失败了什么,我无法进行调试。任何指针都会有所帮助!