我有一个无状态会话bean,我想使用@EJB注入另一个无状态会话Bean(无接口LocalBean):
@Path("/user")
@LocalBean
@Stateless(mappedName = "ejb/UserServiceRest")
public class UserServiceRest extends BaseServiceFacadeRest<User, String> {
@EJB(mappedName = "ejb/userService")
private UserServiceBeanLocal userService;
public UserServiceRest() {}
public getService() {return userService;}
// ... etc
注入的豆是:
@Stateless(mappedName="ejb/UserService")
public class UserServiceBean extends BaseServiceBean<User, String> implements UserServiceBeanRemote, UserServiceBeanLocal {
public UserServiceBean() {}
// ... etc
现在我使用第一个bean作为基于Jersey JAX-RS的webapp的REST端点:
@ApplicationPath("/rest")
public class MyPortalApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register root resource
classes.add(UserServiceRest.class);
return classes;
}
}
之后我点击127.0.0.1:8080/myapp/rest/user
UserServiceRest能够处理传入的请求,但是userService字段没有实例化,@ EJB没有注入UserServiceBeanLocal实例,因此userService为null。
我想知道缺少什么,因为我将它注入另一个EJB它应该按预期工作。