我正在开发一个应用程序,它为MySql数据库使用七个数据源(ds)。当它工作时,我对结果非常满意。但是当我重新部署我的应用程序时,我得到的是与数据源相关的问题。
以下是我在my-application-ds.xml中配置的七个ds中的一个:
<xa-datasource>
<jndi-name>jdbc/my_db_name</jndi-name>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:mysql://192.168.26.2:3306/my_db_name</xa-datasource-property>
<xa-datasource-property name="User">user</xa-datasource-property>
<xa-datasource-property name="Password">password</xa-datasource-property>
<min-pool-size>0</min-pool-size>
<max-pool-size>5</max-pool-size>
<idle-timeout-minutes>5</idle-timeout-minutes>
<exception-sorter-class-name>
com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
</exception-sorter-class-name>
<valid-connection-checker-class-name>
com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
</valid-connection-checker-class-name>
<track-connection-by-tx/>
</xa-datasource>
我认为我已经根据我在网上发现的所有内容正确配置了这个。
1。部署应用程序运行测试确定
2。重新部署应用程序,运行测试NOK
10:07:23,865 WARN [JBossManagedConnectionPool]尝试获取新连接时可抛出:null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.lang.NullPointerException)
at org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory.createManagedConnection(XAManagedConnectionFactory.java:144)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:577)
at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:262)
at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:500)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:341)
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:315)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:396)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
at net.saphety.billing_core.dblayer.datasource.HibernateSession.configure(HibernateSession.java:58)
at net.saphety.billing_core.dblayer.datasource.HibernateSessionFactory.getHibernateSession(HibernateSessionFactory.java:25)
at net.saphety.billing_core.dblayer.datasource.HibDaoCRUD.<init>(HibDaoCRUD.java:35)
at net.saphety.billingcorewebapp.web.FilterHibernateControlSession.doFilter(FilterHibernateControlSession.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:426)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:137)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:107)
at com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.getXAConnection(MysqlXADataSource.java:47)
at org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory.createManagedConnection(XAManagedConnectionFactory.java:136)
... 34 more
之后,休眠抱怨方言......
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
at net.saphety.billing_core.dblayer.datasource.HibernateSession.configure(HibernateSession.java:62)
at net.saphety.billing_core.dblayer.datasource.HibernateSessionFactory.getHibernateSession(HibernateSessionFactory.java:25)
at net.saphety.billing_core.dblayer.datasource.HibDaoCRUD.<init>(HibDaoCRUD.java:35)
at net.saphety.billingcorewebapp.web.FilterHibernateControlSession.doFilter(FilterHibernateControlSession.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
3。重新部署* -ds.xml文件并运行测试NOK,没有任何反应......在我的浏览器中,我收到一个空白的回复。
4。重新部署应用程序,一切正常。 :S
MySql服务器有足够的连接可用。
我有其他项目的数据源,但有一个oracle服务器,没有问题。所以它与MySql有关但我无法弄清楚是什么。
答案 0 :(得分:2)
这些问题看起来像MySql问题,所以你应该检查那里的日志。
Caused by: java.lang.NullPointerException
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:426)
表示与MySql连接时出现故障。给定您与MySql实例的连接数量。可能是连接无效,但JBoss正在尝试重用它。
尝试更改要使用的数据库连接:
<min-pool-size>1</min-pool-size>
甚至为零,不仅仅是在启动时获取池连接。另请参阅是否可以配置MySql以允许更多同时连接。现在只是你的JBoss部署将在启动时占用35个连接,并且最多需要140个连接。你真的需要这么多的连接,并且MySql实例被配置为处理那么多。如果没有,请让这些参数更加符合要求,您的问题应该会变得更好。
答案 1 :(得分:0)
一个答案。我们有时会发现我们需要关闭服务器;从部署中删除测试,数据和工作(如果你不是旧的那些,那就是记录下来)。并重新启动服务器。大多数情况下,当我们运行不稳定的代码时,就会发生这种情当JBoss再次启动时,将重新生成这些文件夹。有关这些文件夹的详细信息,请参阅this webpage。