În Spring Framework 6.0 accesul dedicat EJB a fost eliminat. În Spring Framework 5.x accesul la EJB se face folosind
LocalStatelessSessionProxyFactoryBean, SimpleRemoteStatelessSessionProxyFactoryBean,
LocalSlsbInvokerInterceptor și SimpleRemoteSlsbInvokerInterceptor găsite în org.springframework.ejb.access .
Aceste clase pot fi menționate în fișiere XML Spring, cum ar fi application-config.xml.
Iată un exemplu al acestui caz de utilizare:
<bean id="myEjb" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
Ele pot fi, de asemenea, menționate în fișiere Java astfel:
import org.springframework.ejb.access.*;
@Bean
public SimpleRemoteStatelessSessionProxyFactoryBean myEjb() {
SimpleRemoteStatelessSessionProxyFactoryBean factory = new SimpleRemoteStatelessSessionProxyFactoryBean();
}
Această regulă semnalează utilizarea org.springframework.ejb.access pachet în Java .class fișiere sau .xml fișiere.
Pentru Spring 6.0 utilizați JNDI direct prin JndiObjectFactoryBean în fișierele Java sau jee:jndi-lookup ÎN .xml fișiere.
Iată un exemplu cu JndiObjectFactoryBean:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jndi.JndiObjectFactoryBean;
import com.example.ejb.MyRemoteBean;
@Configuration
public class EjbJndiConfig {
@Bean
public JndiObjectFactoryBean myRemoteEjb() {
JndiObjectFactoryBean jndiBean = new JndiObjectFactoryBean();
jndiBean.setJndiName("java:global/myApp/MyRemoteBean!com.example.ejb.MyRemoteBean");
jndiBean.setProxyInterface(MyRemoteBean.class);
jndiBean.setLookupOnStartup(false); // delay lookup if needed
return jndiBean;
}
}
Iată un exemplu cu jee-jndi-lookup:
<beans xmlns=" http://www.springframework.org/schema/beans " xmlns:jee=" http://www.springframework.org/schema/jee " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance ".... <jee:jndi-lookup id="myEjb" jndi-name="java:global/myApp/MyRemoteBean!com.example.ejb.MyBean" proxy-interface="com.example.ejb.MyBean" /> </beans>
Pentru informaţii suplimentare, vedeţi resursele următoare: