N'utilisez pas les classes d'accès aux EJB dédiées à Spring pour consulter les EJB

Dans Spring Framework 6.0, l'accès dédié aux EJB a été supprimé. Dans le cadre de Spring 5.x, l'accès à l'EJB se fait à l'aide de la fonction LocalStatelessSessionProxyFactoryBean, SimpleRemoteStatelessSessionProxyFactoryBean, LocalSlsbInvokerInterceptor et SimpleRemoteSlsbInvokerInterceptor que l'on trouve dans le org.springframework.ejb.access .

Ces classes peuvent être référencées dans les fichiers XML Spring tels que application-config.xml.

Voici un exemple de ce cas d'utilisation :

<bean id="myEjb" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">

Ils peuvent également être référencés dans les fichiers Java de la manière suivante :


import org.springframework.ejb.access.*;	
@Bean
public SimpleRemoteStatelessSessionProxyFactoryBean myEjb() {
    SimpleRemoteStatelessSessionProxyFactoryBean factory = new SimpleRemoteStatelessSessionProxyFactoryBean();
}

Cette règle signale l'utilisation de l'option org.springframework.ejb.access dans le paquet Java .class ou .xml . Pour Spring 6.0, utilisez directement JNDI via JndiObjectFactoryBean dans les fichiers Java ou jee:jndi-lookup dans .xml .

Voici un exemple avec 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;
    }
}

Voici un exemple avec 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>

Pour plus d'informations, voir les ressources suivantes :