-
access remote ejb
Hello, sorry for my bad english.
I am trying to access my remote ejb (3) by using SimpleRemoteStatelessSessionProxyFactoryBean bean.
My EJBs are on glassfish, well deployed, and I can access them on a standalone client with the following code:
Code:
try{
Properties jndiProps = new Properties();
jndiProps.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
jndiProps.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
jndiProps.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
Context ic= new InitialContext(jndiProps);
System.out.println("Connection done, trying to get remote EJB...");
TestRemote test= (TestRemote) ic.lookup("ejb/TestBean");
System.out.println(test.sayHello("BOB"));
}catch(Exception e){
e.printStackTrace();
}
Unhappily, I am not able to do the same thing with spring.
This is my applicationContext:
Code:
<bean id="jndiContext"
class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.sun.enterprise.naming.SerialInitContextFactory</prop>
<prop key="java.naming.factory.url.pkgs">com.sun.enterprise.naming</prop>
<prop key="java.naming.factory.state">com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl</prop>
</props>
</property>
</bean>
<bean id="testRemote" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean" >
<property name="jndiEnvironment">
<props>
</props>
</property>
<property name="jndiName">
<value>ejb/TestBean</value>
</property>
<property name="businessInterface">
<value>app.TestRemote</value>
</property>
<property name="jndiTemplate">
<value>jndiContext</value>
</property>
</bean>
<bean name="simpleController" class="app.SimpleController">
<property name="testRemote" ref="testRemote"/>
</bean>
To give all informations, this is:
SimpleController:
Code:
package app;
public class SimpleController{
private TestRemote testRemote;
public TestRemote getTestRemote() {
return testRemote;
}
public void setTestRemote(TestRemote testRemote) {
this.testRemote = testRemote;
}
public void doJob(){
System.out.println(this.testRemote.sayHello("BOB"));
}
}
My EJBs implementation and interface
interface:
Code:
@Remote
public interface TestRemote{
public String sayHello(String name);
}
implementation
Code:
@Stateless(name="TestBean", mappedName="ejb/TestBean")
public class TestBean implements TestRemote{
@PersistenceContext(unitName="springejbUnit")
protected EntityManager entityManager;
public String sayHello(String name){
return "Hello " + name;
}
}
And I obtain the following error I start my application:
Code:
Exception in thread "main" org.springframework.remoting.RemoteLookupFailureException: EJB instance [app._TestRemote_Wrapper@e86f8585] is not a Remote Stateless Session Bean
at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance(AbstractRemoteSlsbInvokerInterceptor.java:228)
at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.getSessionBeanInstance(SimpleRemoteSlsbInvokerInterceptor.java:110)
at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.doInvoke(SimpleRemoteSlsbInvokerInterceptor.java:75)
at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.invoke(AbstractRemoteSlsbInvokerInterceptor.java:140)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy6.sayHello(Unknown Source)
at app.SimpleController.doJob(SimpleController.java:16)
at app.Main.main(Main.java:20)
Does someone knows what's happening?
Thanks in advance.
-
Finally it is ok when I use Spring 2.5.5 and jee:* tags.