[jboss-jira] [JBoss JIRA] Commented: (JBAS-8818) CDI injection not working in WebListeners

Marius Bogoevici (JIRA) jira-events at lists.jboss.org
Wed Jan 19 15:33:49 EST 2011


    [ https://issues.jboss.org/browse/JBAS-8818?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12576619#comment-12576619 ] 

Marius Bogoevici commented on JBAS-8818:
----------------------------------------

Nik,

I don't seem to be able to reproduce this in 6.0.0.Final - I tried deploying a project with a hacky listener in [1] and everything worked fine. (Message is a Singleton EJB)

I am also a bit confused about the description: it is said in the description that beanManager is null, but the stacktrace seems to indicate a lookup on a non-null object. Which one is it?

Could you provide a small example that helps reproducing the issue?

[1]
@WebListener
public class MyListener implements HttpSessionListener
{
   @Inject
   BeanManager beanManager;

   @PostConstruct
  public void doAfterConstruction()
   {
     System.out.println(this.getClass() + " session postConstruct " + beanManager);
      Set<Bean<?>> messages =  beanManager.getBeans("message");

      Bean bean = messages.iterator().next();
      System.out.println(((Message) bean.create(beanManager.createCreationalContext(bean))).doSomething());

   }

   public void sessionCreated(HttpSessionEvent httpSessionEvent)
   {
      System.out.println(this.getClass() + " session initialized " + beanManager);
      beanManager.getBeans("message");
   }

   public void sessionDestroyed(HttpSessionEvent httpSessionEvent)
   {
  
   }

}

> CDI injection not working in WebListeners
> -----------------------------------------
>
>                 Key: JBAS-8818
>                 URL: https://issues.jboss.org/browse/JBAS-8818
>             Project: JBoss Application Server
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: Weld/CDI
>    Affects Versions: 6.0.0.Final
>            Reporter: Nicklas Karlsson
>            Assignee: Marius Bogoevici
>
> CDI injection is not performed for WebListeners, e.g.
> @WebListener
> public class BugListener implements HttpSessionListener
> {
>    @Inject
>    BeanManager beanManager;
>    ...
> }
> Will have beanManager==null when the methods are hit

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list