JBoss Seam:组件注入 POJO,但不注入会话 Bean
我有一个处理登录的 Seam 组件,名称为“authenticator”:
@Name("authenticator")
public class AuthenticatorAction implements Authenticator
{
@PersistenceContext
private EntityManager em;
@In(required=false)
@Out(required=false, scope = SESSION)
private User user;
public boolean authenticate(){ ... }
}
这工作得很好,Seam 注入了 EntityManager 实例。但是,一旦我添加 @Stateless
注释,注入就不会发生!在这种情况下,进入 authenticate()
方法时,EntityManager 实例为 null。另一个有趣的注意事项是,对于我拥有的一个单独的有状态会话 bean,只有当我将其设为静态时,才会注入该类中的 Logger 实例。如果我有它非静态的,它不会被注入。这对于记录器来说很好,但是对于像这样的无状态会话 bean,我显然不能为这些组件提供静态成员变量。
我很困惑,因为这个验证器正是 Seam 预订示例中的样子:注入了一个私有成员变量的无状态会话 bean。
有什么想法吗?
I have a Seam component that handles login, with the name "authenticator":
@Name("authenticator")
public class AuthenticatorAction implements Authenticator
{
@PersistenceContext
private EntityManager em;
@In(required=false)
@Out(required=false, scope = SESSION)
private User user;
public boolean authenticate(){ ... }
}
This works just fine, Seam injects the EntityManager instance. However, as soon as I add the @Stateless
annotation, none of the injection happens! In this case, the EntityManager instance is null upon entry to the authenticate()
method. Another interesting note is that with a separate stateful session bean I have, the Logger instance in that class is only injected if I make it static. If i have it non-static, it is not injected. Thats fine for the logger, but for stateless session beans like that, I obviously can't have static member variables for these components.
I'm confused because this authenticator is exactly how it is in the Seam booking example: a stateless session bean with a private member variable being injected.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很好奇:
所以我希望您的Authenticator接口标记有@javax.ejb.Local或@javax.ejb.Remote。如果没有,那么你的 Stateless 将无法按预期工作。
当您拥有 @Stateless Session bean 时,您必须激活 Seam 拦截器才能启用 @In-jection。类似
ejb-jar.xml 的内容如下所示
如果可能,请查看 Seam Security与 JavaOne 的 Dan Allen 合作,他是《Seam in Action》一书的作者。
问候,
I am curious:
So i hope your Authenticator interface is marked with @javax.ejb.Local or @javax.ejb.Remote. If not, so your Stateless will not work as expected.
When you have a @Stateless Session bean, you must activate a Seam interceptor in order to enable @In-jection. Something like
ejb-jar.xml is shown as follows
If possible, take a look at Seam Security with Dan Allen, at JavaOne, author of Seam in Action book.
regards,