在 Spring Framework 6.0 中,专用的 EJB 访问已被删除。 在 Spring Framework 5.x 中,EJB 访问是使用
LocalStatelessSessionProxyFactoryBean, SimpleRemoteStatelessSessionProxyFactoryBean,
LocalSlsbInvokerInterceptor 和 SimpleRemoteSlsbInvokerInterceptor 中发现的 org.springframework.ejb.access 。
这些类可在 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 ,直接通过 JndiObjectFactoryBean Java 文件中 或 jee:jndi-lookup 在 .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>
有关更多信息,请参阅以下资源: