【发布时间】:2015-12-29 15:36:59
【问题描述】:
我有几个 EJB 3.x 无状态会话 bean,它们没有定义接口。我需要将这些 bean 注入 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 具有本地接口视图,因为它是业务接口;但是,我没有(也不能介绍)。
非常感谢任何帮助!
【问题讨论】:
-
这是我能找到的最接近的相关问题:stackoverflow.com/questions/23008810/… -- 但它需要使用远程和本地接口视图,这对我来说不是一个选项。
-
EJB、CDI(如
@Named所暗示的那样。因此,您所说的“控制器”现在由 CDI 而非 Spring 管理)、您应该使用的 JPA 等是其中的一部分Java EE。是什么让您仍然坚持使用 Spring,即您使用 Spring 的哪些功能在 Java EE 中不可用? (这没有争议,而是一个一般用例)。