【发布时间】:2017-02-28 08:51:54
【问题描述】:
我是 jax-rs 的新手,我被子资源困住了。看看吧。
这不行
@Path(..)
public class Test
{
@Path(...)
public SubResource getSub(){
return new SubResource();
}
}
public class SubResource {
@Inject
private MyBean myBean;
@GET
public String getStr(){
return myBean.getStr(); // myBean is null, injection didnt work properly
}
这行得通,但为什么????
@Path(..)
public class Test
{
@Context
private ResourceContext context;
@Path(...)
public SubResource getSub(){
return context.getResource(SubResource.class);
}
}
public class SubResource{
@Inject
private MyBean myBean;
@GET
public String getStr(){
return myBean.getStr(); // myBean is not null anymore, why?
}
为什么 CDI 注入与 ResoureContext 一起使用?
【问题讨论】:
标签: java rest jakarta-ee jax-rs cdi