JBoss Seam:注入到POJO中的组件,而不是Session Bean [英] JBoss Seam: components injected into POJOs, but not Session Beans

查看:150
本文介绍了JBoss Seam:注入到POJO中的组件,而不是Session Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @Name(authentator)

我有一个Seam组件来处理登录,名称为authentator
public class AuthenticatorAction implements Authenticator
{
@PersistenceContext
private EntityManager em;

@In(required = false)
@Out(required = false,scope = SESSION)
private用户;

public boolean authenticate(){...}

}

这样做很好,Seam注入了EntityManager实例。但是,一旦添加 @Stateless 注释,就不会发生任何注入!在这种情况下,EntityManager实例在进入 authenticate()方法时为空。另一个有趣的注意事项是,使用一个单独的有状态会话bean,我在该类中的Logger实例只有在静态时才会被注入。如果我有非静态,它不会被注入。对于记录器来说,这是非常好的,但是对于这样的无状态会话bean,我显然不能使用这些组件的静态成员变量。



我感到困惑,因为这个认证器是准确地说,在Seam的预订范例中:注入一个私有成员变量的无状态会话bean。



任何想法?

解决方案

我很好奇:


然而,添加@Stateless注释,没有注射发生!


所以我希望你的使用@ javax.ejb.Local或@ javax.ejb.Remote将Authenticator界面标记为。如果没有,那么你的无状态将无法正常工作。



当你有一个@Stateless Session bean时,你必须激活一个Seam拦截器命令启用@ In-jection。像

  pureCharger-jar.jar 
META-INF
ejb-jar.xml
persistence.xml

ejb-jar.xml如下所示

 <?xml version =1.0encoding =UTF-8?> 
< ejb-jar xmlns =http://java.sun.com/xml/ns/javaeexmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi :schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsdversion =3.0>
< interceptors>
<拦截器>
< interceptor-class> org.jboss.seam.ejb.SeamInterceptor< / interceptor-class>
< / interceptor>
< / interceptors>
< assembly-descriptor>
<拦截器绑定>
< ejb-name> *< / ejb-name>
< interceptor-class> org.jboss.seam.ejb.SeamInterceptor< / interceptor-class>
< / interceptor-binding>
< / assembly-descriptor>
< / ejb-jar>

如果可能,请查看 Seam Security with Dan Allen ,在JavaOne,Seam in Action书籍的作者。



问候,


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?

解决方案

I am curious:

However, as soon as I add the @Stateless annotation, none of the injection happens!

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

pureCharger-jar.jar 
    META-INF
        ejb-jar.xml
        persistence.xml

ejb-jar.xml is shown as follows

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
    <interceptors>
        <interceptor>
            <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
        </interceptor>
    </interceptors>
    <assembly-descriptor>
        <interceptor-binding>
            <ejb-name>*</ejb-name>
            <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
        </interceptor-binding>
    </assembly-descriptor>
</ejb-jar>

If possible, take a look at Seam Security with Dan Allen, at JavaOne, author of Seam in Action book.

regards,

这篇关于JBoss Seam:注入到POJO中的组件,而不是Session Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆