Compared with ejb2, ejb3 is much easier to develop. All things can be done with annotations. You do not need to deploy the description file...
All jar packages under jboss6/client should be put into classpath, compress the interface of the EJB server into a jar package into the client, or copy the interface Java file.
How can I view the JNDI Of The EJB container?
When JBoss is started, view the Console
4:05:06, 985 info [jbossaskernel] and supplies:
4:05:06, 985 info [jbossaskernel] JNDI: bean12/remote-com.ly.bean.Bean1
4:05:06, 985 info [jbossaskernel] class: COM. ly. Bean. bean1
4:05:06, 985 info [jbossaskernel] class: COM. ly. Bean. bean2
4:05:07, 001 info [jbossaskernel] JNDI: bean12/remote-com.ly.bean.Bean2
4:05:07, 001 info [jbossaskernel]
JNDI: bean12/remote
4:05:07, 001 info [jbossaskernel] JNDI: bean12
The main architecture of the EJB server is as follows:
-Src
├ ── Com
│ └ ── Ly
│ ├ ── Bean
│ Bean1.java
│ Bean2.java
│ Bean3.java
│
│ ─ ── Impl
│ Bean1impl. Java
│ Bean2impl. Java
│
└-META-INF
Manifest. MF
package com.ly.bean;import javax.ejb.Remote;@Remotepublic interface Bean1 { public void sayBean1();}
package com.ly.bean;import javax.ejb.Remote;@Remotepublic interface Bean2 { public void sayBean2();}
package com.ly.bean;import javax.ejb.Remote;@Remotepublic interface Bean3 { public void sayBean3();}
package com.ly.impl;import javax.ejb.Stateless;import com.ly.bean.Bean1;import com.ly.bean.Bean2;@Stateless(name="bean12")public class Bean1Impl implements Bean1,Bean2 { public void sayBean1() { System.out.println("bean1........."); } public void sayBean2() { System.out.println("bean2........."); }}
package com.ly.impl;import javax.ejb.EJB;import javax.ejb.Stateless;import com.ly.bean.Bean1;import com.ly.bean.Bean2;import com.ly.bean.Bean3;@Stateless(name="bean3")public class Bean2Impl implements Bean3 { @EJB(beanName="bean12") Bean1 bean1; Bean2 bean2; public void sayBean3() { bean1.sayBean1(); bean2.sayBean2(); System.out.println("bean3........."); } @EJB(mappedName="bean12/remote") public void setBean2(Bean2 bean2) { this.bean2 = bean2; }}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
The client code is as follows:
Import Java. util. properties; import javax. naming. context; import javax. naming. initialcontext; import COM. ly. bean. bean3;/*** the JBoss black screen client output is as follows * <br/> * 14:05:09, 481 info [Org. JBoss. bootstrap. impl. base. server. abstractserver [6.0.0.final "Neo"] started in 34 S: 101 Ms <br/> 14:05:37, 717 info [stdout] bean1 ......... <br/> 14:05:37, 733 info [stdout] bean2 ......... <br/> 14:05:37, 733 info [stdout] bean3 ......... <br/> * @ author administrator **/public class client {public static void main (string ARGs []) throws exception {properties pro = new properties (); pro. setproperty ("Java. naming. factory. initial "," org. jnp. interfaces. namingcontextfactory "); pro. setproperty ("Java. naming. provider. URL "," localhost: 1099 "); pro. setproperty ("Java. naming. factory. URL. pkgs "," org. JBoss. naming "); Context context = new initialcontext (Pro); bean3 bean = (bean3) context. lookup ("bean3/remote"); bean. saybean3 (); // Remote Server execution saybean3 method }}
The output in the JBoss startup console is as follows:
N ajp-127.0.0.1-8009
14:05:09, 481 info [org. JBoss. Bootstrap. impl. Base. server. abstractserver] jbossas
[6.0.0.final "Neo"] started in 34 seconds: 101 Ms
14:05:37, 717 info [stdout] bean1 .........
14:05:37, 733 info [stdout] bean2 .........
14:05:37, 733 info [stdout] bean3 .........