I am having problems getting JBoss to inject an environment variable value into a bean. Here is my bean class:
package com.topcoder.test; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.ejb.EJBContext; import javax.ejb.Remote; import javax.ejb.SessionContext; import javax.ejb.Stateless; import javax.ejb.TransactionManagement; import javax.ejb.TransactionManagementType; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContextType; import org.jboss.annotation.ejb.RemoteBinding; import com.topcoder.test.Test; public @Stateless(name = "TestBean") class TestBean implements Test { @Resource(name="managerFile") private String managerFile; public String getManagerFile() { return managerFile; } public String testMethod() { String ret = "the value of managerFile in testMethod() is " + getManagerFile(); return ret; } @PersistenceContext(unitName = "persistenceUnit", type = PersistenceContextType.TRANSACTION) private EntityManager manager; @PersistenceContext(unitName = "persistenceUnit", type = PersistenceContextType.TRANSACTION) public void setEntityManager(EntityManager manager) { this.manager = manager; } public EntityManager getEntityManager() { if (manager == null) { throw new IllegalStateException("EntityManager has not been set on DAO before usage"); } return manager; } @SuppressWarnings("unchecked") public List retrieveAll() throws Exception { EntityManager em = getEntityManager(); List result = em.createQuery("FROM TestEntity").getResultList(); if (result == null) { result = new ArrayList(); } return result; } }
I want the managerFile value to be injected by JBoss. Here is my ejb-jar.xml:
<enterprise-beans>
<session>
<ejb-name>Test</ejb-name>
<ejb-class>com.topcoder.test.TestBean</ejb-class>
<env-entry>
<env-entry-name>managerFile</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>com/topcoder/test/TestBean.properties</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
But I get this error message when I deploy my ear to JBoss:
09:07:40,495 WARN [ResourceHandler] Not injecting managerFile, no matching enc injector env/managerFile found
I am running JBoss 4.2. What am I doing wrong?