无法处理 EJB 的业务接口 class
Failed to process business interfaces for EJB class
在使用测试参数启动 maven 时,出现上述异常。在创建集成测试部署时,我得到以下信息:
org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0466: Failed to process business interfaces for EJB class class ..contract.ContractMockService
有关 class 看起来像这样:
package ..integration.bestand.contract;
import java.time.LocalDate;
import java.util.ArrayList;
import javax.ejb.Local;
import javax.ejb.Stateless;
import org.apache.deltaspike.core.api.exclude.Exclude;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
...
@Exclude(ifProjectStage = {
ProjectStage.Production.class,
ProjectStage.Staging.class,
..Integration.class,
..Qs.class,
..PatchQs.class
})
@Stateless
@Local(IContractIntService.class)
public class ContractMockService implements IContractIntService {
...
return ContractBuilder.build();
}
}
界面 IContractIntService
看起来像:
package ..integration.bestand.contract;
import javax.ejb.Local;
...
@Local
public interface IContractIntService {
public enum State {
SUCCESS,
UNKNOWN_ERROR,
NOT_FOUND;
// TODO: Stati für Fehler hier definieren
}
//Interface comment
Result<State, ContractDTO> retrieveContract(String contractIdentifier);
}
注意:该接口在另一个项目中,通过 maven 包含。
测试看起来像这样:
package ..api.contractregistration.service;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.logging.Logger;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestWatcher;
import org.junit.runner.RunWith;
import ..core.test.IntegrationTest;
@RunWith(Arquillian.class)
@Category(IntegrationTest.class)
public class ContractRegistrationIntegrationTest {
protected final Logger log = Logger.getLogger(ContractRegistrationIntegrationTest.class.getCanonicalName());
@Rule
public TestWatcher watcher = new TestWatcher() {
@Override
protected void starting(org.junit.runner.Description description) {
log.info(String.format("---> Starting test: %s", description));
}
@Override
protected void failed(Throwable e, org.junit.runner.Description description) {
log.info(String.format("<--- Test failed: %s", description));
}
@Override
protected void succeeded(org.junit.runner.Description description) {
log.info(String.format("<--- Test succeeded: %s", description));
}
};
@Deployment
public static WebArchive createDeployment() {
WebArchive result = ShrinkWrap.create(WebArchive.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
.addPackages(true, "..ejb.portal")
.addPackages(true, "..core")
.deletePackages(true, "..core.config.deltaspike")
.addPackages(true, "..integration")
.addPackages(true, "..api")
.addPackages(true, "org.apache.deltaspike.core")
.addPackages(true, "..ejb.util");
System.out.println("########## TEST DEPLOYMENT########" + result.toString(true));
return result;
}
@Test
public void test() {
String tempPw = "bla"; // result.getDto();
assertThat(tempPw, any(String.class));
}
}
这个测试的特别之处在于,我什至没有在测试中使用任何 MockService
。
maven 配置如下所示:
目标:clean test -Parq-wildfly-managed
JRE 虚拟机参数:-Djboss.home="myLocalWildflyDirectory"
JAVA_HOME
设置为jdk8.
最后是我的pom,特别是容器部分"arq-wildfly-managed":
...
<profile>
<!-- An optional Arquillian testing profile that executes tests in your WildFly instance, e.g. for build server -->
<!-- This profile will start a new WildFly instance, and execute the test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
<id>arq-wildfly-managed</id>
<dependencies>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-bestand-mock-ejb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-docservice-mock-ejb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-bestand-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
...
带有 clean verify package install
的正常 Maven 构建(只是不包括测试)构建成功。
注意:为此 post,我重命名了包以排除公司专业化。
类似的错误建议更正 ShrinkWrap 部署,但我实际上包括了所有的包,甚至试图明确包括接口-class。但是,同样的错误仍然存在。
什么可能导致这种情况?
在测试中试试这个 (ShrinkWrap):
.addAsResource(new StringAsset("org.apache.deltaspike.ProjectStage=IntegrationTest"), "META-INF/apache-deltaspike.properties")
并将排除项更改为:
@Exclude(exceptIfProjectStage = ProjectStage.IntegrationTest.class)
如果您需要排除其他阶段,请将它们添加到这个非常排除的语句中
有点晚了,但更好的解决方案如下:
在 ShrinkWrap 部署中,需要使用 shrinkwrap maven 解析器。所以,而不是
.addPackages(true, "org.apache.deltaspike.core")
在 result
的创建中,使用 maven 解析器。应该看起来像这样:
ShrinkWrap
.create(WebArchive.class, "test.war")
.addAsLibraries(
resolver.artifact("org.apache.deltaspike.core")
.resolveAsFiles());
工件是maven artifactId。这将 return 另一个 .war。可以合并多个 .wars(从解析器或您在原始问题中看到的方式创建)。这个合并。war 然后必须从部署方法中 returned。
这背后的原因:
一旦您通过 ShrinkWrap.create.*.addAsPackages..
导入外部包含(在本例中为 deltaspike),它们就会丢失资源,因此这应该只用于内部项目包。要使用 Maven 解析器,您可以在 .pom 文件中包含以下内容:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
感谢 dzone.com 的 Maven 解析器代码片段。我目前正在做另一个项目,所以我无法显示原始代码,但它与此非常相似。
也许这个解决方案将来会对某人有所帮助。
在使用测试参数启动 maven 时,出现上述异常。在创建集成测试部署时,我得到以下信息:
org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0466: Failed to process business interfaces for EJB class class ..contract.ContractMockService
有关 class 看起来像这样:
package ..integration.bestand.contract;
import java.time.LocalDate;
import java.util.ArrayList;
import javax.ejb.Local;
import javax.ejb.Stateless;
import org.apache.deltaspike.core.api.exclude.Exclude;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
...
@Exclude(ifProjectStage = {
ProjectStage.Production.class,
ProjectStage.Staging.class,
..Integration.class,
..Qs.class,
..PatchQs.class
})
@Stateless
@Local(IContractIntService.class)
public class ContractMockService implements IContractIntService {
...
return ContractBuilder.build();
}
}
界面 IContractIntService
看起来像:
package ..integration.bestand.contract;
import javax.ejb.Local;
...
@Local
public interface IContractIntService {
public enum State {
SUCCESS,
UNKNOWN_ERROR,
NOT_FOUND;
// TODO: Stati für Fehler hier definieren
}
//Interface comment
Result<State, ContractDTO> retrieveContract(String contractIdentifier);
}
注意:该接口在另一个项目中,通过 maven 包含。
测试看起来像这样:
package ..api.contractregistration.service;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.logging.Logger;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestWatcher;
import org.junit.runner.RunWith;
import ..core.test.IntegrationTest;
@RunWith(Arquillian.class)
@Category(IntegrationTest.class)
public class ContractRegistrationIntegrationTest {
protected final Logger log = Logger.getLogger(ContractRegistrationIntegrationTest.class.getCanonicalName());
@Rule
public TestWatcher watcher = new TestWatcher() {
@Override
protected void starting(org.junit.runner.Description description) {
log.info(String.format("---> Starting test: %s", description));
}
@Override
protected void failed(Throwable e, org.junit.runner.Description description) {
log.info(String.format("<--- Test failed: %s", description));
}
@Override
protected void succeeded(org.junit.runner.Description description) {
log.info(String.format("<--- Test succeeded: %s", description));
}
};
@Deployment
public static WebArchive createDeployment() {
WebArchive result = ShrinkWrap.create(WebArchive.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
.addPackages(true, "..ejb.portal")
.addPackages(true, "..core")
.deletePackages(true, "..core.config.deltaspike")
.addPackages(true, "..integration")
.addPackages(true, "..api")
.addPackages(true, "org.apache.deltaspike.core")
.addPackages(true, "..ejb.util");
System.out.println("########## TEST DEPLOYMENT########" + result.toString(true));
return result;
}
@Test
public void test() {
String tempPw = "bla"; // result.getDto();
assertThat(tempPw, any(String.class));
}
}
这个测试的特别之处在于,我什至没有在测试中使用任何 MockService
。
maven 配置如下所示:
目标:clean test -Parq-wildfly-managed
JRE 虚拟机参数:-Djboss.home="myLocalWildflyDirectory"
JAVA_HOME
设置为jdk8.
最后是我的pom,特别是容器部分"arq-wildfly-managed":
...
<profile>
<!-- An optional Arquillian testing profile that executes tests in your WildFly instance, e.g. for build server -->
<!-- This profile will start a new WildFly instance, and execute the test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
<id>arq-wildfly-managed</id>
<dependencies>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-bestand-mock-ejb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-docservice-mock-ejb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ivi.torino</groupId>
<artifactId>torino-integration-bestand-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
...
带有 clean verify package install
的正常 Maven 构建(只是不包括测试)构建成功。
注意:为此 post,我重命名了包以排除公司专业化。
类似的错误建议更正 ShrinkWrap 部署,但我实际上包括了所有的包,甚至试图明确包括接口-class。但是,同样的错误仍然存在。
什么可能导致这种情况?
在测试中试试这个 (ShrinkWrap):
.addAsResource(new StringAsset("org.apache.deltaspike.ProjectStage=IntegrationTest"), "META-INF/apache-deltaspike.properties")
并将排除项更改为:
@Exclude(exceptIfProjectStage = ProjectStage.IntegrationTest.class)
如果您需要排除其他阶段,请将它们添加到这个非常排除的语句中
有点晚了,但更好的解决方案如下:
在 ShrinkWrap 部署中,需要使用 shrinkwrap maven 解析器。所以,而不是
.addPackages(true, "org.apache.deltaspike.core")
在 result
的创建中,使用 maven 解析器。应该看起来像这样:
ShrinkWrap
.create(WebArchive.class, "test.war")
.addAsLibraries(
resolver.artifact("org.apache.deltaspike.core")
.resolveAsFiles());
工件是maven artifactId。这将 return 另一个 .war。可以合并多个 .wars(从解析器或您在原始问题中看到的方式创建)。这个合并。war 然后必须从部署方法中 returned。
这背后的原因:
一旦您通过 ShrinkWrap.create.*.addAsPackages..
导入外部包含(在本例中为 deltaspike),它们就会丢失资源,因此这应该只用于内部项目包。要使用 Maven 解析器,您可以在 .pom 文件中包含以下内容:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
感谢 dzone.com 的 Maven 解析器代码片段。我目前正在做另一个项目,所以我无法显示原始代码,但它与此非常相似。
也许这个解决方案将来会对某人有所帮助。