在 Spring Framework 6.0 中,專用的 EJB 存取已被移除。 在 Spring Framework 5.x 中,EJB 存取是使用
LocalStatelessSessionProxyFactoryBean, SimpleRemoteStatelessSessionProxyFactoryBean,
LocalSlsbInvokerInterceptor 和 SimpleRemoteSlsbInvokerInterceptor 中找到的類別 org.springframework.ejb.access 套件中使用了 Apache XMLBeans 類別。
這些類別可以在 Spring XML 檔案中引用,例如 application-config.xml.
以下是此使用個案的範例:
<bean id="myEjb" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
它們也可以像這樣在 Java 檔案中被引用:
import org.springframework.ejb.access.*;
@Bean
public SimpleRemoteStatelessSessionProxyFactoryBean myEjb() {
SimpleRemoteStatelessSessionProxyFactoryBean factory = new SimpleRemoteStatelessSessionProxyFactoryBean();
}
此規則標記使用 org.springframework.ejb.access 套件中 Java .class 檔案或 .xml 檔案。
對於 Spring 6.0 直接使用 JNDI,透過 JndiObjectFactoryBean Java 檔案中 或 jee:jndi-lookup in .xml 檔案。
以下是一個範例 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;
}
}
以下是一個範例 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>
如需相關資訊,請參閱下列資源: