Non utilizzare le classi di accesso EJB dedicate di Spring per cercare EJB

In Spring Framework 6.0 è stato rimosso l'accesso dedicato agli EJB. In Spring Framework 5.x l'accesso a EJB viene effettuato utilizzando il metodo LocalStatelessSessionProxyFactoryBean, SimpleRemoteStatelessSessionProxyFactoryBean, LocalSlsbInvokerInterceptor e SimpleRemoteSlsbInvokerInterceptor che si trovano nella cartella org.springframework.ejb.access pacchetto.

Queste classi possono essere referenziate nei file XML di Spring, come ad esempio application-config.xml.

Ecco un esempio di questo caso d'uso:

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

Si può anche fare riferimento ai file Java in questo modo:


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

Questa regola segnala l'utilizzo dell'opzione org.springframework.ejb.access pacchetto in Java .class o .xml file. Per Spring 6.0 utilizzare direttamente JNDI tramite JndiObjectFactoryBean nei file di Java o jee:jndi-lookup in .xml file.

Ecco un esempio con 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;
    }
}

Ecco un esempio con 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>

Per ulteriori informazioni, consultare le seguenti risorse: