我们有一个项目使用:
如果出现以下错误,Weld将无法初始化:
org.jboss.weld.exceptions.DeploymentException: WELD-001423 无法启用相同的备选bean类 [com.mycompany.AltBean in jar:file:/C:/Users/Me/.m2/repository/com/mycompany/project/version-SNAPSHOT/project-version-SNAPSHOT-tests.jar!/META-INF/beans.xml@8, com.mycompany.AltBean in jar:file:/C:/Users/Me/.m2/repository/com/mycompany/project/version-SNAPSHOT/project-version-SNAPSHOT-tests.jar!/META-INF/beans.xml@8] 在beans.xml中。
换句话说,它似乎对
- Weld-SE进行依赖注入
- 静态本地方法调用本地库
@PrepareForTest
)似乎会干扰Weld的初始化。例如,如果我有以下内容:@RunWith(PowerMockRunner.class)
@PrepareForTest(StaticNativeAPI.class)
public class Test {
@Before
public void setup() {
WeldContainer wc = new Weld().initialize();
}
}
如果出现以下错误,Weld将无法初始化:
org.jboss.weld.exceptions.DeploymentException: WELD-001423 无法启用相同的备选bean类 [com.mycompany.AltBean in jar:file:/C:/Users/Me/.m2/repository/com/mycompany/project/version-SNAPSHOT/project-version-SNAPSHOT-tests.jar!/META-INF/beans.xml@8, com.mycompany.AltBean in jar:file:/C:/Users/Me/.m2/repository/com/mycompany/project/version-SNAPSHOT/project-version-SNAPSHOT-tests.jar!/META-INF/beans.xml@8] 在beans.xml中。
at org.jboss.weld.manager.Enabled.createMetadataMap(Enabled.java:123)
at org.jboss.weld.manager.Enabled.<init>(Enabled.java:94)
at org.jboss.weld.manager.Enabled.of(Enabled.java:79)
at org.jboss.weld.bootstrap.BeanDeployment.<init>(BeanDeployment.java:114)
at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:184)
at org.jboss.weld.bootstrap.WeldBootstrap$DeploymentVisitor.visit(WeldBootstrap.java:153)
at org.jboss.weld.bootstrap.WeldBootstrap.startContainer(WeldBootstrap.java:284)
at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.startContainer(ForwardingBootstrap.java:42)
at org.jboss.weld.environment.se.Weld.initialize(Weld.java:129)
at com.mycompany.Test.setup(Test.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:56)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:43)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:104)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:234)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:133)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:188)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:166)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:101)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
换句话说,它似乎对
beans.xml
进行了两次解析。有人知道如何让这两个库很好地协作吗?