-
1. Re: Dependecy Injection in JMX Service Object
echon Apr 12, 2006 6:46 AM (in response to echon)if a datasource is not injected it's not a problem, because i can get it from JNDI, but how can i get the EntityManager (peristence unit already created)?
-
2. Re: Dependecy Injection in JMX Service Object
echon Apr 12, 2006 4:24 PM (in response to echon)no statement to this?
-
3. Re: Dependecy Injection in JMX Service Object
echon Apr 13, 2006 11:55 AM (in response to echon)is it a bug or not?
-
4. Re: Dependecy Injection in JMX Service Object
bill.burke Apr 13, 2006 1:21 PM (in response to echon)you mean, why is it null before start()? Like in the constructor?
-
5. Re: Dependecy Injection in JMX Service Object
echon Apr 13, 2006 2:13 PM (in response to echon)the JMX Component has the standard lifecycle methods:
create(), start(),stop(), destroy()
My code looks like this:@Service(objectName = "portal:service=SystemPropertyService") @Management(SystemPropertyManagement.class) @Local(SystemPropertyLocal.class) @LocalBinding(jndiBinding = SystemPropertyLocal.JNDI) public class SystemPropertyService implements SystemPropertyLocal, SystemPropertyManagement { private static final Log _log = LogFactory .getLog(SystemPropertyService.class); private final ConcurrentHashMap<String, String> _properties = new ConcurrentHashMap<String, String>(); @PersistenceContext(unitName = "portalEM") protected EntityManager em; public void create() throws Exception { } public void start() throws Exception { List<SystemProperty> properties = _getProperties(); // add Properties } public void stop() { _properties.clear(); } public void destroy() { } @SuppressWarnings("unchecked") @TransactionAttribute(TransactionAttributeType.REQUIRED) private List<SystemProperty> _getProperties() { try { List<SystemProperty> list = em.createQuery("from SystemProperty sp").getResultList(); em.flush(); return list; } catch (RuntimeException e) { throw new SystemException(e); } } }
I get a NullPointerException in _getProperties() because em is null.
I would accept it if the EntityManager is not injected while constructor or create(), but why in start()? And why is this behaviour different since CR2?
The EntityManager is not injected before the start() method is completly processed. ( before: null, start(): null, after: injected)
In 4.0.4RC1 i can use the EntityManager in the start() method,
in 4.0.4CR2 it is null (same Sourcecode).
I also tried to inject only a datasource by @Resource and it was also not injected (but available by JNDI and InitialContext in start() method).
In both versions the EntityManager is available when the service is started.
This is a little bit curious. Do you have an explanation for this behaviour?
Regads
Peter -
6. Re: Dependecy Injection in JMX Service Object
echon Apr 17, 2006 11:15 AM (in response to echon)no statement? I only want to know, if this is a bug or if this behaviour will also exist in the final version of 4.0.4.
Regards
Peter -
7. Re: Dependecy Injection in JMX Service Object
bill.burke Apr 17, 2006 11:21 AM (in response to echon)I'll log a bug in jira. We changed the behavior for service beans to fix another bug.
Another release is scheduled before java one. -
9. Re: Dependecy Injection in JMX Service Object
bdecoste Apr 19, 2006 6:12 PM (in response to echon)I just corrected this issue and closed the JIRA task. The fix will be available in the next release of EJB3
-
10. Re: Dependecy Injection in JMX Service Object
bjornbjorn May 10, 2006 3:01 AM (in response to echon)I also get EntityManager null when trying to inject it in a servlet with 404RC2. When using it in the processRequest() method it is null.
Could this be the same issue? -
11. Re: Dependecy Injection in JMX Service Object
echon May 10, 2006 6:27 AM (in response to echon)dependency injections don't work for servlets. This bug only affects jmx service objects whith lifecycle methods.
Regards
Peter -
12. Re: Dependecy Injection in JMX Service Object
cleanerx Aug 5, 2007 8:30 AM (in response to echon)@EJB annotations cannot be injected within @Service Beans. The behavior changed from 4.0.4Patch1 to > 4.2. The injected @EJB references are null within the start method of the jmx bean. However the @PersistenceContext annotation can be injected. I'm just curious if I'm missing something or if it's a bug.