我运行了JBoss 4.2 AppServer,并定义了mysql-ds.xml。我还有一组自定义jar,我想部署为mbean,它使用有界MySQL连接作为java:/ MySqlDS。
但是,似乎在数据源有界之前加载了jar。
有没有办法确保在数据源有界之后加载MBean?
以下是日志条目:
11:39:29,639 FATAL [DatasourceConnectionProvider] Could not find datasource: java:/MySqlDS
javax.naming.NameNotFoundException: MySqlDS not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
...
11:39:29,666 ERROR [HibernateUtil] Building SessionFactory failed.
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
...
Caused by: javax.naming.NameNotFoundException: MySqlDS not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
... 106 more
然后是:
11:39:30,524 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:/MySqlDS'
答案 0 :(得分:0)
好的,我只需要在我的MBean声明中添加一个depends语句:
<depends>jboss.jca:service=DataSourceBinding,name=MySqlDS</depends>