I am using JPA with Hibernate implementation and EJB 2.1 in my project (a Spring + Hibernate project). After I deployed my project to JBoss 6.0 CR1 the server log said:
15:34:20,866 INFO [EjbDeployer] installing bean: ejb/ejbproject.jar#EBMyBean,uid27484928
15:34:20,867 INFO [EjbDeployer] with dependencies:
15:34:20,870 INFO [EjbDeployer] and supplies:
15:34:20,871 INFO [EjbDeployer] jndi:EBMyBean
15:34:20,873 INFO [EjbDeployer] jndi:local/EBMyBean@3124254开发者_JAVA技巧1
15:34:21,038 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=myproject.ear/ejbproject.jar#persistenceUnit
15:34:21,196 INFO [Version] Hibernate Commons Annotations 3.2.0.Final
The server didn't start properly and at the end it threw an exception saying:
Caused by: javax.naming.NameNotFoundException: EBMyBean not bound
In JMX console of JBoss I cannot see anything under Ejb 2.1 Module section. My EAR file contains a jar file and a war file. All ejbs and persistence unit are in the jar file.
In META-INF folder of my jar file there are ejb-jar.xml and persistence.xml files but I don't have jboss.xml specified. I have a beanRefContext.xml outside that folder, as well as some bean definition files.
ejb-jar.xml is like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC
'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<!--========================================-->
<!-- EBMyBean -->
<!--========================================-->
<entity>
<description></description>
<ejb-name>EBMyBean</ejb-name>
<local-home>com.ejb.EBMyBeanHome</local-home>
<local>com.ejb.EBMyBean</local>
<ejb-class>com.ejb.EBMyBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
</entity>
<enterprise-beans>
</ejb-jar>
I also made a test project of a simple EJB 2.1 session bean without Hibernate and deployed it. The server log, however, is different:
15:30:46,658 INFO [EjbDeployer] installing bean: ejb/#HiEJB,uid14009391
15:30:46,658 INFO [EjbDeployer] with dependencies:
15:30:46,659 INFO [EjbDeployer] and supplies:
15:30:46,660 INFO [EjbDeployer] jndi:HiEJB
15:30:46,660 INFO [EjbDeployer] jndi:HiEJB/com.test.HiRemote
15:30:46,697 INFO [EjbModule] Deploying HiEJB
15:30:46,904 INFO [ProxyFactory] Bound EJB Home 'HiEJB' to jndi 'HiEJB'
In JMX console I can see some jndi objects under Ejb 2.1 Module section and the server starts OK.
It seems the beans in my first project haven't bound to jndi objects. But how can I fix this?
I will answer my own question.
Clearly the entity beans are not bound to the jndi objects. The reason is the name provided by default could not be inserted into jndi pools. In this case it is local/EBMyBean@31242541. If I specify a local-jndi-name property in a jboss.xml file I am able to insert the object into jndi pool.
I use something like this:
<!DOCTYPE jboss PUBLIC
"-//JBoss//DTD JBOSS 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
<jboss>
<enterprise-beans>
<entity>
<ejb-name>EBMyBean</ejb-name>
<local-jndi-name>ejb/EBMyBean</local-jndi-name>
</entity>
</enterprise-beans>
</jboss>
Then the jndi name is ejb/EBMyBean and I am able to find that in jmx-console. This is tested in JBoss 6.0 Final.
精彩评论