简体   繁体   中英

How to deploy EJB 3.0 application in Wildfly 8 application server

I am migrating EJB 3.0 application from jboss AS 6 to wildfly AS 8.

Is it possible to deploy EJB 3.0 application to wildfly as ease in wildfly? After updating the EJB spec as per wildfly EJB modules in pom.xml, I am getting compilation error that below symbols are not found as the related APIs are not available in wildfly.

org.jboss.ejb3.annotation.LocalBinding;
org.jboss.ejb3.annotation.Depends;
org.jboss.ejb3.annotation.Management;
org.jboss.ejb3.annotation.Service;

The above annotations are found in jboss-ejb3-ext-api.jar and it is a part of jBoss 6 AS.

javax.annotation.security.PermitAll

The above annotations are found in jboss-annotations-api_1.1_spec.jar and it is a part of jBoss 6 AS.

From the documentation, I understood that wildfly support EJB3.2 and EJB3.2 does not support @LocalBinding / @RemoteBinding. So how will I do the same in wildfly using standalone.xml / ejb-jar.xml / any other configuration .

I tried following the blog: JBoss: Binding values into JNDI in JBoss EAP 6 similar to JNDIBindingServiceMgr but could not link where I tried to lookup EJB bean based on jndi name but did not work.

Please help. Many Thanks.

Annotate you bean interface with @Remote and or @Local. Annotate you bean implementation with @Stateless.

Build the project with maven to generate EJB JAR and the client JAR (exclude your server implementation if it is used outside of your EAR).

<build>
    <plugins>
        <!-- maven-ejb-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <configuration>
                <clientExcludes>
                    <clientExclude>**/ejb/*</clientExclude>
                </clientExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Package the EJB in a EAR. (This is optional, but I deploy the web module as one .ear file).

To be able to know the JNDI Name of you EJB, Wildfly follow the standard naming convention. `java:global///

For example ear has the name my-ear , ejb name my-ejbs and the bean interface abcMyBeanRemote and the implementation abcejb.MyBean : Remote JNDI path will be java:global/my-ear/my-ejbs/MyBean or more verbose java:global/my-ear/my-ejbs/MyBean!abcMyBeanRemote .

To generate this structure of deployment I use the following configuration in my ear project:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <version>7</version>
                <applicationId>my-ear</applicationId>
                <applicationName>my-ear</applicationName>
                <defaultLibBundleDir>/lib</defaultLibBundleDir>
                <jboss>
                    <version>5</version>
                    <unauthenticated-principal>guest</unauthenticated-principal>
                    <security-domain>ABC</security-domain>
                </jboss>
                <modules>
                    <webModule>
                        <groupId>a.b.c.my-group</groupId>
                        <artifactId>my-web-app</artifactId>
                        <uri>my-web-app.war</uri>
                        <contextRoot>/my-web-app</contextRoot>
                    </webModule>
                    <ejbModule>
                        <groupId>a.b.c.my-group</groupId>
                        <artifactId>my-ejbs</artifactId>
                        <uri>my-ejbs.jar</uri>
                    </ejbModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>

<applicationName>my-ear</applicationName> will set the right name used by my application EAR (without the version).

<uri>my-ejbs.jar</uri> will remove the version of my ejb module, so it is not reflected in the JNDI path.

Hints : The JNDI name of your bean is printed in the log file when the EAR is deployed.

If you want to access the bean from outside the application server, you must use the JNDI path that begin with java:jboss/exported

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM