JBOSS JNDI Bindings

阅读更多

http://docs.jboss.org/ejb3/app-server/tutorial/jndibinding/jndi.html

JNDI Bindings
By default, session beans will bind to JNDI in the form ejbName/remote for remote interfaces and ejbName/local in the case of local interfaces. When the EJBs are deployed in an .ear file, the default jndi binding will be prepended by the name of the .ear file. So if the ear file name is foo.ear the default jndi names would be foo/EJB-NAME/remote and foo/EJB-NAME/local. You can override this behavior by defining your own @org.jboss.ejb3.LocalBinding or @org.jboss.ejb3.remoting.RemoteBinding.

 

Local Interface JNDI Binding.
To change the JNDI name for your local interface use the org.jboss.ejb3.LocalBinding annotation.


@Stateless
@LocalBinding(jndiBinding="custom/MySession")
public class MySessionBean implements MySession
{
}

 


Remote Interface JNDI Binding
To change the JNDI name for your remote interface use the org.jboss.ejb3.RemoteBindings annotation.


@Stateless
@RemoteBinding(jndiName="custom/remote/MySession")
public class MySessionBean implements MySession
{
}

 

Persistence unit JNDI Bindings
Persistence units are not bound into JNDI by default. You can bind them by defining some jboss specific properties in persistence.xml.
         
            
                java:/DefaultDS
                MyApp.jar
                org.acme.Employee
                org.acme.Person
                org.acme.Address
               
                  
                  
               
            
         

 

Client
Open up Client.java. You'll see that it looks up the stateless bean under "Calculator". Also notice that there is no Home interface and you can begin executing on the stateless bean right away.


Building and Running
To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
Unix:    $ export JBOSS_HOME=
Windows: $ set JBOSS_HOME=
$ ant
$ ant run

run:
     [java] 1 + 1 = 2
     [java] 1 - 1 = 0

 

Jar structure
EJB 3.0 beans must be packaged in a JAR file with the suffix .jar. Running the ant script above creates a JAR file within the deploy/ directory of JBoss. All that needs to be in that jar is your server-side class files. So basically just the CalculatorBean and the interfaces it implements. JBoss will automatically browse the JAR file to determine if any EJBs are annotated by any classes within it. THere is no precompilation step.

 

你可能感兴趣的:(JBoss,Ant,EJB,Bean,UP)