JBoss Seam: components introduced in POJO but not Beans session

I have a Seam component that processes a 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 fine, Seam introduces an EntityManager instance. However, as soon as I add the @Stateless , none of the injections happen! In this case, the EntityManager instance is null when entering the authenticate() method. Another interesting point is that with a separate session with a bean state I have, a Logger instance in this class is introduced only if I make it static. If I have it non-static, it is not introduced. Thats fine for the registrar, but for a session without beans state like me, I obviously can't have static member variables for these components.

I am confused because this authenticator is exactly the same as in the Seam booking example: a session without a bean with the private member variable entered.

Any ideas?

+3
source share
1 answer

I am curious:

However , when I add the @Stateless annotation , none of the injections happen!

So, I hope your authentication interface is marked with @ javax.ejb.Local or @ javax.ejb.Remote. If not, then your Stateless will not work properly.

When you have an @Stateless Session bean, you must activate the Seam hook to enable @ In-jection. Sort of

 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, check out Seam Security with Dan Allen , on JavaOne, author of Seam in Action.

Respectfully,

+4
source

Source: https://habr.com/ru/post/1306663/


All Articles