It's Wildfly 9.0.2.
One: New wildfly 9.0.2 Server in MyEclipse (how to create a new web search)
II: Modify the argument of the Wildfly server (in run configurations, not in preference)
Add-B 172.16.15.142 after program arguments
Three: New EJB project, new interface and Bean
Ejb1.java:
1 Package ejb100; 2 3 Public Interface Ejb1 {4 Public string SayHello (string name); 5 }
Ejb1bean.java:
1 Packageejb100;2 3 ImportJavax.ejb.Remote;4 Importjavax.ejb.Stateless;5 6 @Stateless7 @Remote8 Public classEjb1beanImplementsEJB1 {9 @OverrideTen Publicstring SayHello (string name) { One //TODO auto-generated Method Stub A return"Hello," +name; - } -}
IV: Deployment The EJB Project add to the server and operate directly on the MyEclipse
Four: New Java project
1. Add Jboss-client.jar to build path
2. Add the corresponding EJB service folder in the deployment folder in the standalone folder in the JBoss folder to the build path
3. Writing test procedures
1 Packageejb100test;2 3 Importjava.util.Properties;4 5 ImportJavax.naming.Context;6 ImportJavax.naming.InitialContext;7 Importjavax.naming.NamingException;8 9 Importejb100. EJB1;Ten One Public classEjb100test { A - Public Static voidMain (string[] args)throwsnamingexception { - //TODO auto-generated Method Stub theProperties prop =NewProperties (); -Prop.put (context.url_pkg_prefixes, "org.jboss.ejb.client.naming"); -InitialContext context =NewInitialContext (prop); - +EJB1 test = (EJB1) context.lookup ("ejb:/ejb100/ejb1bean!" + Ejb1.class. GetName ()); -System.out.println (Test.sayhello ("Yingzhongwen")); + } A at}
Note that the address here is ejb:/module/bean-simple-name!interface-full-name. Note case
Add jboss-ejb-client.properties under the SRC folder
1endpoint.name=client-Endpoint2Remote.connectionprovider.create.options.org.xnio.options.ssl_enabled=false3 4remote.connections=default5 6Remote.connection.default. host=172.16.15.1427Remote.connection.default. port=81808Remote.connection.default. connect.options.org.xnio.options.sasl_policy_noanonymous=false9Remote.connection.default. username=EjbuserTenRemote.connection.default. password=ejbuser
Because I changed the port offset value to 100 in the Standalone.xml, so the default port8080 becomes 8180.
The deployed EJB service can be seen through the 127.0.0.1:10090 (port offset) Web URL.
****************************************************************************
Note that the whole process is prone to mistakes:
1. Forget to add Jboss-client.jar to build path
2. Jboss-ejb-client.properties configuration errors, such as IP, port, etc.
3. Context.lookup The path is wrong, although the EJB console is written in the beginning of the Java:global address, but the test found that the address is not used, need to use the address of the beginning of the EJB, the other case is also easy to ignore the problem
4. You do not need to use tools such as ant or Export to make the EJB into a jar package, if you put the jar package into the deployment, then note that it needs to put its jar in the build path, and the path in Context.lookup should be the same: EJB :/jar-name/bean-simple-name!interface-full-name.
*****************************************************************************
Call other EJB services inside the server:
Injection.java:
1 Package ejb200; 2 3 Public Interface Injection {4 Public String SayHello (); 5 }
Injectionbean.java
1 Packageejb200;2 3 ImportJavax.ejb.EJB;4 ImportJavax.ejb.Remote;5 Importjavax.ejb.Stateless;6 7 Importejb100. EJB1;8 9 @StatelessTen@Remote (injection.class) One Public classInjectionbeanImplementsInjection { A @EJB - PrivateEjb1 ejb1; - @Override the PublicString SayHello () { - //TODO auto-generated Method Stub - returnEjb1.sayhello ("Yingzhongwen"); - } + -}
You just need to redeploy a little bit.
Ejb:remote Call