How to inject a Session Bean into a Message Driven Bean?

Could you try to define things like this: @Remote public interface TestBeanRemote { public void doSomething(); } @Stateless(name="TestBeanRemote") public class TestBean implements TestBeanRemote { public void doSomething() { // business logic goes here } } And then in the MDB: @MessageDriven(mappedName = "jms/mvs.TestController", activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms. Queue") }) public class TestController implements MessageListener { @EJB(beanName="TestBeanRemote") private TestBeanRemote testBean; public TestController() { } public void onMessage(Message message) { testBean.doSomething(); } } If this work, I'll try to provide an explanation :).

Sorry, unfortunately that doesn't work either. I think I'll go with what I found out about IoC. Thanks anyway!

– Hank Mar 18 '10 at 7:46 @Hank Weird, my understanding it that it should. I'm confused... – Pascal Thivent Mar 18 '10 at 7:58.

It seems that my problem was related to Inversion of Control and caused by my lack of knowledge and Netbeans' suggestions for Class/Interface names. I found out that - in order to find the the right bean and the right interface - I should name them properly. Here's what works: @Remote public interface Test { public void doSomething(); } @Stateless public class TestBean implements Test { public void doSomething() { // business logic goes here } } And in the MDB I access 'Test' not 'TestBean': @MessageDriven(mappedName = "jms/mvs.TestController", activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.

Queue") }) public class TestController implements MessageListener { @EJB private Test testBean; public TestController() { } public void onMessage(Message message) { testBean.doSomething(); } }.

– Pascal Thivent Mar 18 '10 at 8:05 Try here: java.sun. Com/blueprints/code/namingconventions. Html – Hank Mar 18 '10 at 8:34 Ok, I'm starting to understand this more and more now.

My example above would be correct, if the interface would be @Local. When I inject a session bean into something, I'm injecting . The container then tries to find the implementing class (Bean) as well as the appropriate interface (for @Local use: or Local, for @Remote use: Remote).

So the problem wasn't JNDI, it was not complying with the naming conventions! – Hank Mar 18 '10 at 8:47.

Ok, I found out that if I add the annotation @LocalBean to the session bean, it works. What the ...?

I'm a bit further now. @LocalBean identifies a bean without an Interface. So this is not what I want, even though it works :D – Hank Mar 18 '10 at 7:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions