[jboss-user] [EJB 3.0] - Re: @EJB annotation injection broken in 4.0.5.GA
doktora
do-not-reply at jboss.com
Wed Apr 11 14:01:22 EDT 2007
I've been testing two aspects: stateless beans and MBeans.
Here is all the code:
SomeBean -- stateless bean, it will be injected into TestBean.
package test;
|
| @javax.ejb.Stateless
| @javax.ejb.Local(SomeIntr.class)
| public class SomeBean implements SomeIntr
| {
| public String test() {
| System.out.println("SomeBean::test()");
| return "SomeBean::test()";
| }
| }
TestBean -- a steless bean which has SomeBean injected, I have tried to clarify EJB with beanName, etc. -- same effect. In 4.0.5.GA this prints "Hello: null".
package test;
|
| @javax.ejb.Stateless
| @javax.ejb.Local(TestIntr.class)
| public class TestBean implements TestIntr
| {
| @javax.annotation.EJB
| SomeIntr some;
|
| public void hello() {
| System.out.println("Helllo: " + some);
| if(some!=null) some.test();
| }
| }
This an MBean which tries to access TestBean in a few different ways -- injection, lookup, etc.
Calling testme() on this mbean prints "TEST ME: null / null".
Then after lookup and the call ti.hello() also prints "Helllo: null".
| package test;
|
| import javax.management.ObjectName;
| import javax.management.MBeanServer;
| import javax.management.MBeanRegistration;
| import javax.annotation.EJB;
| import javax.naming.InitialContext;
| import javax.naming.Context;
| import org.jboss.annotation.ejb.Service;
|
|
| public class TestService implements TestServiceMBean, MBeanRegistration
| {
|
| @EJB //(beanName="data/TestBean/local")
| TestIntr test;
|
| TestIntr test2;
|
| @EJB //(beanName="data/TestBean/local")
| public void setTest(TestIntr ti) { test2 = ti; }
|
| public void testme()
| {
| System.out.println("TEST ME: " + this.test + " / " + this.test2);
|
| try {
| InitialContext ctx = new InitialContext();
| TestIntr ti = (TestIntr)ctx.lookup("data/TestBean/local");
| System.out.println("TestIntr via lookup: " + ti);
| ti.hello();
|
|
| } catch(Exception e) {
| System.out.println("Could not lookup TestIntr: " + e.getMessage());
| e.printStackTrace();
| }
| }
|
| public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
| System.out.println("TestService ::::::::::::: preRegister");
| return name;
| }
|
| public void postRegister(Boolean registrationDone) {
| System.out.println("TestService ::::::::::::: postRegister");
| }
|
| public void preDeregister() throws Exception {
| System.out.println("TestService ::::::::::::: preDeregister");
| }
|
| public void postDeregister() {
| System.out.println("TestService ::::::::::::: postDeregister");
| }
|
| public void start() throws Exception {
| System.out.println("TestService ::::::::::::: start: " + this.test);
| testme();
| }
| public void stop() throws Exception {
| System.out.println("TestService ::::::::::::: stop");
| }
| }
|
For completeness, here are the corresponding interfaces:
package test;
public interface SomeIntr
| {
| public String test();
| }
TestBean interface:
| package test;
|
| public interface TestIntr
| {
| public void hello();
| }
TestService interface
package test;
|
| import org.jboss.annotation.ejb.Management;
|
| public interface TestServiceMBean
| {
| public void testme();
|
| public void start() throws Exception;
| public void stop() throws Exception;
|
| }
To test this, I executed TestService.testme() from the JMX console.
Here are some more JBoss details:
[Server] Release ID: JBoss [Zion] 4.0.5.GA (build: CVSTag=Branch_4_0 date=200610162339)
| [Server] Server Name: default
| [Server] Root Deployment Filename: jboss-service.xml
| [ServerInfo] Java version: 1.5.0_07,Apple Computer, Inc.
| [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_07-87,"Apple Computer, Inc."
| [ServerInfo] OS-System: Mac OS X 10.4.9,i386
And this is from jboss-service.xml:
| <mbean code="clairetest.TestService" name="clairetest:service=testservice">
| </mbean>
Let me know if further info would be of use and if anyone can confirm this.
As I mentioned, JB405 was installed in EJB3-clustered mode via the jems installer.
--doktora
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036471#4036471
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036471
More information about the jboss-user
mailing list