You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by beto <se...@gmail.com> on 2014/03/10 11:10:49 UTC
“Injection data not found in JNDI context” when injecting TimerService via @Resource
I'm to trying use a TimerService instance to schedule dynamically some
executions on a singleton EJB on a Tomee 1.6.0 server. The scheduling works
the first time, but on subsequent executions I get the following error (in
the Tomee console) and scheduling seem to stop working in the app:
mar 07, 2014 1:27:06 PM org.apache.openejb.cdi.CdiResourceInjectionService
fillInjectionProperties
WARNING: Injection data not found in JNDI context:
jndiName='comp/env/myapp.Bean/timerService', target=myapp.Bean/timerService
The EJB trying to achieve this looks like this:
package myapp;
@Singleton
public class Bean implements Serializable {
private static final long serialVersionUID = 1L;
@Resource
private transient TimerService timerService;
private Timer oldTimer = null;
public Bean() {
super();
}
public void schedule(
@Observes(during = TransactionPhase.AFTER_COMPLETION)
@ScheduleEvent ScheduleExpression schedule) {
if (oldTimer != null) {
oldTimer.cancel();
}
try {
return oldTimer = timerService.createCalendarTimer(schedule, new
TimerConfig("TIMER", true));
} catch (IllegalArgumentException e) {
throw new EJBException(e);
}
}
@Timeout
@Lock(LockType.READ)
private void timeout(Timer timer) {
// Do stuff...
}
}
The method schedule of Bean is triggered on an event fired from ConfigBean,
which monitors a ".properties" file (where the schedule timing information
is stored) and fires the necessary event whenever it detects any changes on
it:
@Singleton
@Startup
public class ConfigBean implements Serializable {
@Inject
@ScheduleEvent
private Event<ScheduleExpression> scheduleEvent;
//...
private load() {
//...
//Loading routine
//...
scheduleEvent.fire(ScheduleExpressionFactory.parse(scheduleExpression));
}
//...
}
Why does Tomee find the injection data the first time, and it doesn't the
next ones? How can I get it to work?
http://stackoverflow.com/questions/22251299/injection-data-not-found-in-jndi-context-when-injecting-timerservice-via-reso
<http://stackoverflow.com/questions/22251299/injection-data-not-found-in-jndi-context-when-injecting-timerservice-via-reso>
--
View this message in context: http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: "Injection data not found in JNDI context" when injecting
TimerService via @Resource
Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
I have the during attr in my sample.
Could you give it a try?
JLouis
2014-03-11 14:28 GMT+01:00 beto <se...@gmail.com>:
> I finally solved it! It seems that the @Observes(during =
> TransactionPhase.AFTER_COMPLETION) annotation was causing the issue.
> Removing the parameter and leaving simply @Observes did the trick for me.
>
> I don't know really why, but the problem, perhaps, is related to
> transactional behaviour implied in TransactionPhase.AFTER_COMPLETION. The
> default behaviour of the method after removing that is non-transactional
> (see documentation).
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149p4668160.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
--
Jean-Louis
Re: "Injection data not found in JNDI context" when injecting
TimerService via @Resource
Posted by beto <se...@gmail.com>.
I finally solved it! It seems that the @Observes(during =
TransactionPhase.AFTER_COMPLETION) annotation was causing the issue.
Removing the parameter and leaving simply @Observes did the trick for me.
I don't know really why, but the problem, perhaps, is related to
transactional behaviour implied in TransactionPhase.AFTER_COMPLETION. The
default behaviour of the method after removing that is non-transactional
(see documentation).
--
View this message in context: http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149p4668160.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: "Injection data not found in JNDI context" when injecting
TimerService via @Resource
Posted by Romain Manni-Bucau <rm...@gmail.com>.
well the best would be to reproduce it in a sample you can share, (mvn
test -> fail would be awesome)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-03-10 12:02 GMT+01:00 beto <se...@gmail.com>:
> Not that I know. I don't know if the container does it instead during the
> flow I described: ConfigBean fires the event on startup and Bean calls
> timerService.createCalendarTimer. If ConfigBean fires the event again, the
> warning is issued and the problem reproduces.
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149p4668151.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: "Injection data not found in JNDI context" when injecting
TimerService via @Resource
Posted by beto <se...@gmail.com>.
Not that I know. I don't know if the container does it instead during the
flow I described: ConfigBean fires the event on startup and Bean calls
timerService.createCalendarTimer. If ConfigBean fires the event again, the
warning is issued and the problem reproduces.
--
View this message in context: http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149p4668151.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: "Injection data not found in JNDI context" when injecting
TimerService via @Resource
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
would need more context, do you serialize the bean?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-03-10 11:10 GMT+01:00 beto <se...@gmail.com>:
> I'm to trying use a TimerService instance to schedule dynamically some
> executions on a singleton EJB on a Tomee 1.6.0 server. The scheduling works
> the first time, but on subsequent executions I get the following error (in
> the Tomee console) and scheduling seem to stop working in the app:
>
> mar 07, 2014 1:27:06 PM org.apache.openejb.cdi.CdiResourceInjectionService
> fillInjectionProperties
> WARNING: Injection data not found in JNDI context:
> jndiName='comp/env/myapp.Bean/timerService', target=myapp.Bean/timerService
> The EJB trying to achieve this looks like this:
>
> package myapp;
>
> @Singleton
> public class Bean implements Serializable {
> private static final long serialVersionUID = 1L;
>
> @Resource
> private transient TimerService timerService;
>
> private Timer oldTimer = null;
>
> public Bean() {
> super();
> }
>
> public void schedule(
> @Observes(during = TransactionPhase.AFTER_COMPLETION)
> @ScheduleEvent ScheduleExpression schedule) {
>
> if (oldTimer != null) {
> oldTimer.cancel();
> }
>
> try {
> return oldTimer = timerService.createCalendarTimer(schedule, new
> TimerConfig("TIMER", true));
> } catch (IllegalArgumentException e) {
> throw new EJBException(e);
> }
> }
>
> @Timeout
> @Lock(LockType.READ)
> private void timeout(Timer timer) {
> // Do stuff...
> }
> }
> The method schedule of Bean is triggered on an event fired from ConfigBean,
> which monitors a ".properties" file (where the schedule timing information
> is stored) and fires the necessary event whenever it detects any changes on
> it:
>
> @Singleton
> @Startup
> public class ConfigBean implements Serializable {
> @Inject
> @ScheduleEvent
> private Event<ScheduleExpression> scheduleEvent;
>
> //...
> private load() {
> //...
> //Loading routine
> //...
>
> scheduleEvent.fire(ScheduleExpressionFactory.parse(scheduleExpression));
> }
> //...
> }
> Why does Tomee find the injection data the first time, and it doesn't the
> next ones? How can I get it to work?
>
> http://stackoverflow.com/questions/22251299/injection-data-not-found-in-jndi-context-when-injecting-timerservice-via-reso
> <http://stackoverflow.com/questions/22251299/injection-data-not-found-in-jndi-context-when-injecting-timerservice-via-reso>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: "Injection data not found in JNDI context" when injecting
TimerService via @Resource
Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Hi,
I haven't been able to reproduce, but maybe I did not understand.
Could check that example
http://people.apache.org/~jlmonteiro/cdi-events.tar.gz
And give it a try, please?
Lemm me know, if that is the same use case.
JLouis
2014-03-10 11:10 GMT+01:00 beto <se...@gmail.com>:
> I'm to trying use a TimerService instance to schedule dynamically some
> executions on a singleton EJB on a Tomee 1.6.0 server. The scheduling works
> the first time, but on subsequent executions I get the following error (in
> the Tomee console) and scheduling seem to stop working in the app:
>
> mar 07, 2014 1:27:06 PM org.apache.openejb.cdi.CdiResourceInjectionService
> fillInjectionProperties
> WARNING: Injection data not found in JNDI context:
> jndiName='comp/env/myapp.Bean/timerService', target=myapp.Bean/timerService
> The EJB trying to achieve this looks like this:
>
> package myapp;
>
> @Singleton
> public class Bean implements Serializable {
> private static final long serialVersionUID = 1L;
>
> @Resource
> private transient TimerService timerService;
>
> private Timer oldTimer = null;
>
> public Bean() {
> super();
> }
>
> public void schedule(
> @Observes(during = TransactionPhase.AFTER_COMPLETION)
> @ScheduleEvent ScheduleExpression schedule) {
>
> if (oldTimer != null) {
> oldTimer.cancel();
> }
>
> try {
> return oldTimer = timerService.createCalendarTimer(schedule,
> new
> TimerConfig("TIMER", true));
> } catch (IllegalArgumentException e) {
> throw new EJBException(e);
> }
> }
>
> @Timeout
> @Lock(LockType.READ)
> private void timeout(Timer timer) {
> // Do stuff...
> }
> }
> The method schedule of Bean is triggered on an event fired from ConfigBean,
> which monitors a ".properties" file (where the schedule timing information
> is stored) and fires the necessary event whenever it detects any changes on
> it:
>
> @Singleton
> @Startup
> public class ConfigBean implements Serializable {
> @Inject
> @ScheduleEvent
> private Event<ScheduleExpression> scheduleEvent;
>
> //...
> private load() {
> //...
> //Loading routine
> //...
>
> scheduleEvent.fire(ScheduleExpressionFactory.parse(scheduleExpression));
> }
> //...
> }
> Why does Tomee find the injection data the first time, and it doesn't the
> next ones? How can I get it to work?
>
>
> http://stackoverflow.com/questions/22251299/injection-data-not-found-in-jndi-context-when-injecting-timerservice-via-reso
> <
> http://stackoverflow.com/questions/22251299/injection-data-not-found-in-jndi-context-when-injecting-timerservice-via-reso
> >
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Injection-data-not-found-in-JNDI-context-when-injecting-TimerService-via-Resource-tp4668149.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
--
Jean-Louis