The
Session bean can be published in addition to annotations, using the appropriate configuration file. In this case, there is no need to use annotations in interfaces and session beans. Two files are required to configure the session bean in JBoss. These two documents are Ejb-jar.xml and Jboss.xml. These two files should be in the Meta-inf directory, which should be placed in the root directory of the jar file. The Ejb-jar.xml file is responsible for configuring the session bean, and the following is a typical configuration code:
<?xml version= "1.0" encoding= "ASCII"
<ejb-jar xmlns:xsi= "http://www.w3.org/2001/" Xmlschema-instance "xmlns=" Http://java.sun.com/xml/ns/javaee "
xmlns:ejb=" http://java.sun.com/xml/ns/javaee/ Ejb-jar_3_0.xsd "
xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ Ejb-jar_3_0.xsd "
version=" 3.0
<display-name>myejb</display-name>
< Enterprise-beans>
<session>
<ejb-name>greeter</ejb-name>
<busi Ness-local>service. Greeterbeanlocal</business-local>
<business-remote>service. Greeterbeanremote</business-remote>
<ejb-class>service. Greeterbean</ejb-class>
<session-type>stateless</session-type>
<transaction -type>container</transaction-type>
</session>
</enterprise-beans>
</EJB-JAR&G T
Where the <ejb-name> element is a representation that represents the name of the currently configured session Bean. <business-local> and <bussiness-remote> are used to specify local and remote interfaces, respectively. <ejb-class> Java class to specify session Bean
The Jboss.xml file is used primarily to specify Jndi, as shown in the following code:
<?xml version="1.0"?>
<jboss xmlns:xs="http://www.jboss.org/j2ee/schema"
xs:schemaLocation="http://www.jboss.org/j2ee/schema jboss_5_0.xsd"
version="5.0">
<enterprise-beans>
<session>
<ejb-name>Greeter</ejb-name>
<jndi-name>mygreeter</jndi-name>
<local-jndi-name>mygreeter_local</local-jndi-name>
</session>
</enterprise-beans>
</jboss>
The value of the <ejb-name> element in the code above is the same as the value of the <ejb-name> element to be ejb-jar.xml. <jndi-name> used to specify a remote Jndi name. <local-jndi-name> use to specify the name of the local jndi. If you are accessing a remote session bean, you can use the following code:
Properties prop = new Properties();
InitialContext ctx = new InitialContext();
System.out.println(((service.Greeter)ctx.lookup("mygreeter")).greet("bill"));
As you can see from the code above, the Lookup method finds the session bean on the server side through "Mygreeter".