Using remote EJBs in spring beans

To inject a reference to remote session bean into application context put the following lines into your application context definition:

 <bean id="someBean" lazy-init="true"
    class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    <property name="jndiName" value="/DictionaryFacade" />
    <property name="businessInterface" value="com.programmingnotepad.EJBInterface" />
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="refreshHomeOnConnectFailure" value="true" />
    <property name="lookupHomeOnStartup" value="false" />
    </bean>

    <bean id="jndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.provider.url">localhost:1099</prop>
                <prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
                <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
            </props>
        </property>
    </bean>

Then you can inject your bean simply using Autowired:

@Service
public class SomeSpringBean {
    @Autowired
    @Qualifier("someBean")
    private EJBInterface;
}
Advertisements