简体   繁体   English

在JBoss EAP 6上的JAX-RS中进行CDI注入

[英]CDI injection in JAX-RS on JBoss EAP 6

I've got a JAX-RS class: 我有一个JAX-RS课:

@Path("/")
@RequestScoped
public class Customer {
    @Inject
    private CustomerDAO cDao;
}

Where CustomerDAO is a POJO and I've got an empty beans.xml in WEB-INF. 在CustomerDAO是POJO的地方,我在WEB-INF中有一个空的beans.xml。

ciao remains null. ciao仍然为空。 I've tried scattering @ManagedBean, @Stateless, @Named, etc. around and nothing seems to make much difference. 我试过在周围散布@ ManagedBean,@ Stateless,@ Named等,似乎没有什么区别。 Any suggestions? 有什么建议么? How can you even debug this? 你怎么甚至可以调试呢?

I suppose your Customer Rest Resource is not in the same jar with the beans.xml file. 我想您的Customer休息资源与beans.xml文件不在同一个jar中。 After packaging, unzip the jar file to check that. 打包后,解压缩jar文件以进行检查。

I had an Application class that looked something like this: 我有一个Application类,看起来像这样:

public class MyApplication extends Application {

    private Set<Object> resourceObjects = new HashSet<Object>();

    public MyApplication() {
        resourceObjects.add(new Customer());
    }
    @Override
    public Set<Object> getSingletons() {
        return resourceObjects;
    }
}

It turns out that (i) I didn't need to put anything in the body of this class for it to still work and that (ii) by calling new I was skipping CDI. 事实证明,(i)我不需要在此类的主体中放置任何内容即可使它继续工作,并且(ii)通过调用new来跳过CDI。 Not overriding getSingletons fixes the behaviour. 不覆盖getSingletons可修复该行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM