Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » CDI injection in an entity listener using Tomcat and Weld doesn't appear to work(Dependency injection into an entity listener when using Tomcat 8 and Weld 2.1 fails because the BeanManager cannot be found)
CDI injection in an entity listener using Tomcat and Weld doesn't appear to work [message #1698075] Wed, 10 June 2015 21:01
Jonathan Zimmerman is currently offline Jonathan ZimmermanFriend
Messages: 1
Registered: June 2015
Junior Member
Hi all,
I'm trying to set up dependency injection into an entity listener using @Inject annotations in my listener.

My entity:
@Entity
@EntityListeners({ CampaignListener.class })
public class Campaign {
  private Long campaignId;

  @Id
  private Long getId() {
    return campaignId;
  }

  private void setId(final Long campaignId) {
    this.campaignId = campaignId;
  }
}


My listener:
public class CampaignListener {
  @Inject MyBean myBean;

  @PreRemove
  public void beforeRemoveCampaign(final Campaign campaign) {
    myBean.foo(); // throws NullPointerException!
  }

myBean.foo() throws a NullPointerException.

After a little digging I discovered that EclipseLink, internally, is unable to find the BeanManager:
package org.eclipse.persistence.internal.sessions.cdi;
...

public class EntityListenerInjectionManagerImpl implements EntityListenerInjectionManager {
  public EntityListenerInjectionManagerImpl(Object beanManagerInstance) throws NamingException {
        if (beanManagerInstance == null) {
            Context context = new InitialContext();
            beanManagerInstance = context.lookup("java:comp/BeanManager"); // throws NamingException!
        }
      ...
    }
  ...
}

context.lookup("java:comp/BeanManager") throws a NamingException.

When using Weld with Tomcat the BeanManager lives at "java:comp/env/BeanManager", so of course this will not work.

Is this a bug or a limitation? I'm using Weld 2.1.2.Final, EclipseLink 2.6.1-RC1, and Tomcat 8.0.20.

Thanks!
Previous Topic:MOXy: Is it possible to generate xml node name based on the value of another attribute
Next Topic:Using @NamedPLSQLStoredFunctionQuery with boolean IN param, 'SYS.SQLJUTL' not installed
Goto Forum:
  


Current Time: Fri Feb 26 06:43:04 GMT 2021

Powered by FUDForum. Page generated in 0.01332 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top