0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Arquillian+Glassfish Embedded Containerでは、ConversationScopedなbeanをインジェクトできない!?

Posted at

環境

  • JDK 1.8.0 u31 (x64)
  • NetBeans IDE 8.0.2
  • Arquillian core 1.1.7.Final
  • Arquillian Glassfish container 1.0.0.CR4

ソース

こんな風にConversationScopedをつけたクラスを用意しました。

MyBean.java
@ConversationScoped
public class MyBean implements Serializable {
  // (略)
}

上記クラスをテストするためのクラスを用意しました。

MyBeanTest.java
@RunWith(Arqullian.class)
public class MyBeanTest {
    @Deployment
    public static Archive<?> createDeployment() {
        return ShrinkWrap.create(WebArchive.class).addClass(MyBean.class);
    }

    @Inject
    private MyBean myBean;
    // (略)
}

結果

テストを実行すると、MyBeanをインジェクトできなくて失敗します。

Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001408: Unsatisfied dependencies for type MyBean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private MyBeanTest.instance
  at MyBeanTest.instance(MyBeanTest.java:0)

考察

こんなコードを付け加えてBeanManagerに取り扱ってもらえているかどうか確認すると、MyBeanは入っていません。

BeanManager bm = CDI.current().getBeanManager();
Set<Bean<?>> beans = bm.getBeans(Object.class, new AnnotationLiteral<Any>(){});
for (Bean<?> bean:beans) {
    System.out.println(bean.getBeanClass().getName());
}

ConversationScopedではなく、ApplicationScopedやRequestScopedなどではちゃんとインジェクトできます。

何か追加で書かないといけないコードがあるのかもしれません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?