ユニットテスト用のMavenプロジェクトがあり、CDIを使用したいと思います。私は次のようにpom.xmlにweld-se依存関係を置きました:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>1.1.8.Final</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP3</version>
</dependency>
JUnitテストランナーで溶接をブートストラップしています:
public class WeldJUnit4Runner extends BlockJUnit4ClassRunner {
private final Class klass;
private final Weld weld;
private final WeldContainer container;
public WeldJUnit4Runner(final Class klass) throws InitializationError {
super(klass);
this.klass = klass;
this.weld = new Weld();
this.container = weld.initialize();
}
@Override
protected Object createTest() throws Exception {
final Object test = container.instance().select(klass).get();
return test;
}
}
そして、このランナーを使用した単体テスト。このテストでは、アプリケーションスコープのBeanを注入しています。問題は、アプリケーションスコープのBeanが溶接するのがまったく不明であるかのように、唯一の注入ポイントへの「不満足な依存関係」のために溶接を初期化できないことです。しかし、そのBeanは私のテストではsrc / test / java / ...にあります(ただし、別のJavaパッケージにあります)。
src / test/resourcesに空のbeans.xmlがあります。
開始時に溶接が警告を出すことに気づきましたが、これらが私の問題の原因ではないと思います:
604 [main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
605 [main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
誰かがそれを手伝ってくれる?