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!