我有几个EJB 3.x无状态会话bean,它们没有定义接口。我需要将这些bean注入到Spring bean中,但无法这样做。如何将不带接口的EJB注入到Spring bean中?
无接口EJB:
@Singleton
public class MyNoInterfaceEJB {
public String sayHello() { return "hi"; }
}
我的豆:
@Named
public class MyEJBClientBean {
@EJB
private MyNoInterfaceEJB testejb;
// ...
}
而且我bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<jee:local-slsb id="testejb" jndi-name="java:global/MyEAR/MyModule/MyProject!com.test.MyNoInterfaceEJB"
business-interface="com.test.MyNoInterfaceEJB"/>
<context:annotation-config />
<context:component-scan base-package="com.test" />
</beans>
在Spring容器的初始化,我得到以下错误:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'testejb':
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: [com.test.MyNoInterfaceEJB] is not an interface
异常本身非常清晰 - Spring容器期望我的bean具有本地接口视图,因为它是业务接口;但是,我没有一个(也不能介绍一个)。
任何帮助,非常感谢!
这是我能找到的最接近的相关问题:http://stackoverflow.com/questions/23008810/ejb-3-injection-into-spring-beans - 但它需要使用远程和本地接口视图,它对我来说不是一种选择。 –
EJB,CDI(正如'@ Named'所暗示的那样,因此,您所说的“控制器”现在由CDI而不是Spring来管理),您应该使用的JPA等是Java EE的一部分。什么让你仍然坚持Spring呢,即你在Spring中使用哪些Java EE中没有的特性? (这不是有争议的,而是一般用例)。 – Tiny