我跟随tutorial学习EJB和远程接口。与教程不同,我使用的是IntelliJ,WildFly和Gradle。我在IntelliJ中将EE项目放在一起时遇到了一些麻烦,但在阅读了他们的文档,略读教程等之后。
这里是aPicturesWorthAThousandWords风格的细节:
Gallery with Project/EJB Window images
(抱歉,因为低代表我无法添加图片!)
LibrarySessionRemote:
package com.test.eetestapp;
import javax.ejb.CreateException;
import javax.ejb.Remote;
import java.util.List;
@Remote
public interface LibrarySessionRemote {
void create() throws CreateException;
void addBook(String bookName);
List getBooks();
}
LibrarySessionRemoteBean:
package com.test.eetestapp;
import javax.ejb.CreateException;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import java.util.ArrayList;
import java.util.List;
@Stateless(name = "LibrarySessionEJB")
@Remote(LibrarySessionRemote.class)
@TransactionManagement
public class LibrarySessionRemoteBean implements LibrarySessionRemote {
List<String> bookShelf;
public LibrarySessionRemoteBean() {
this.bookShelf = new ArrayList<>();
}
@Override
public void create() throws CreateException {
}
@Override
public void addBook(String bookName) {
bookShelf.add(bookName);
}
@Override
public List getBooks() {
return bookShelf;
}
}
EJB-jar.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1">
<enterprise-beans>
<session>
<ejb-name>LibrarySessionEJB</ejb-name>
<business-remote>com.test.eetestapp.LibrarySessionRemote</business-remote>
<ejb-class>com.test.eetestapp.LibrarySessionRemoteBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
部署失败/ ClassNotFound异常:
/opt/jdk/jdk1.8.0_102/bin/java -classpath /home/testacc/Apps/idea-IU-162.1447.26/lib/idea_rt.jar:/home/testacc/Apps/idea-IU-162.1447.26/lib/util.jar -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper /tmp/classpath com.intellij.javaee.oss.process.JavaeeProcess 42152 com.intellij.javaee.oss.jboss.agent.JBoss71Agent
[2016-11-18 02:35:45,647] Artifact EjbComponent:ejb: Server is not connected. Deploy is not available.
Connected to server
[2016-11-18 02:35:46,346] Artifact EjbComponent:ejb: Artifact is being deployed, please wait...
[2016-11-18 02:35:47,226] Artifact EjbComponent:ejb: Error during artifact deployment. See server log for details.
[2016-11-18 02:35:47,227] Artifact EjbComponent:ejb: java.lang.Exception: {"WFLYDC0074: Operation failed or was rolled back on all servers. Server failures:" => {"server-group" => {"ha-server-group" => {"host" => {"slave01" => {"ssdp-server01" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"EjbComponent_ejb.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"EjbComponent_ejb.jar\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"EjbComponent_ejb.jar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.test.eetestapp.LibrarySessionRemoteBean from [Module \"deployment.EjbComponent_ejb.jar:main\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: com.test.eetestapp.LibrarySessionRemoteBean from [Module \"deployment.EjbComponent_ejb.jar:main\" from Service Module Loader]"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.unit.\"EjbComponent_ejb.jar\".POST_MODULE"],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}},"slave02" => {"ssdp-server02" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"EjbComponent_ejb.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"EjbComponent_ejb.jar\".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"EjbComponent_ejb.jar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.test.eetestapp.LibrarySessionRemoteBean from [Module \"deployment.EjbComponent_ejb.jar:main\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: com.test.eetestapp.LibrarySessionRemoteBean from [Module \"deployment.EjbComponent_ejb.jar:main\" from Service Module Loader]"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.unit.\"EjbComponent_ejb.jar\".POST_MODULE"],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}}}}}}}
我相信WildFly设置是正确的。我使用的域具有两个主机控制器,每个控制器运行一个服务器(在同一服务器组内)。我通过部署一个简单的.war并查看结果来验证这是有效的。