Eclipse + JBoss 5 + EJB3 Development Guide (5): Using profiles to publish session beans

Source: Internet
Author: User
Tags xmlns jboss root directory

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".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.