google Analytics

Thursday, August 26, 2010

Calling EJB3 from Spring

Calling EJB3 from Spring
=============================================================



=============================================================

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jee="http://www.springframework.org/schema/jee"      
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

   
<bean id="helper" class="com.test.ejb.TestEjbImpl" scope="singleton">
<property name="testenvejb" ref="testenvejb" />
</bean>
<jee:jndi-lookup id="testenvejb" jndi-name="testenvejb">
<jee:environment>
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1300
</jee:environment>
</jee:jndi-lookup>   
</beans>



=============================================================
 

=============================================================
package com.test.ejb;

import org.springframework.beans.factory.annotation.Autowired;

import com.testenv.TestEnvEjbRemote;

public class TestEjbImpl {
    public TestEjbImpl() {
            System.out.println("called");
    }
    @Autowired
    public TestEnvEjbRemote testenvejb;
   
    public void callMe(){
        System.out.println(testenvejb);
        testenvejb.sayHello("ANish");
    }

    public void setTestenvejb(TestEnvEjbRemote testenvejb) {
        this.testenvejb = testenvejb;
    }
   
}
=============================================================




=============================================================
The Ejb
package com.testenv;

import javax.ejb.Stateless;

/**
 * Session Bean implementation class TestEnvEjb ANISH
 */
@Stateless(mappedName = "testenvejb")
public class TestEnvEjb implements TestEnvEjbRemote, TestEnvEjbLocal {

    /**
     * Default constructor.
     */
    public TestEnvEjb() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void sayHello(String name) {
        System.out.println("name------>>>>>>>"+name);
       
    }

}
package com.testenv;
import javax.ejb.Remote;

@Remote
public interface TestEnvEjbRemote {
   
    public void sayHello(String name);

}

package com.testenv;
import javax.ejb.Local;

@Local
public interface TestEnvEjbLocal {

}
===============================



=============================================================

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class TestEjb {
    public static void main(String[] args) {

        XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource(
                "/META-INF/spring/ODSSpring.xml"));
        System.out.println(bf.getBean("helper"));

        TestEjbImpl helper = (TestEjbImpl) bf.getBean("helper");
        helper.callMe();

    }
}





<jee:jndi-lookup/> (with multiple JNDI environment settings)

Using Jee Calling EJB3.0 with Spring
Understanding the jee environment Settings
jndi environment with jee schema

1 comment:

  1. <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:jee="http://www.springframework.org/schema/jee"
           xmlns:util="http://www.springframework.org/schema/util"      
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
    <bean id="helper" class="com.test.ejb.TestEjbImpl" scope="singleton">
    <property name="testenvejb" ref="testenvejb" />
    </bean>
    <jee:jndi-lookup id="testenvejb" environment-ref="myProperties" jndi-name="testenvejb">
    </jee:jndi-lookup>
    <util:properties id="myProperties" location="classpath:com/test/ejb/jndi.properties"/>   
    </beans>

    ReplyDelete