Glassfish4 + EJB + Spring,部署失败 [英] Glassfish4 + EJB + Spring, deploy fails
问题描述
我正在将Glassfish 3.1.2.2上的Java7应用程序升级到Glassfish 4.1上的Java8。该应用程序被打包为一个ear文件,其中包含一个包含远程EJB和Spring bean的jar文件,以及包含几个servlet和一些webservices的war文件。
与Glassfish 3.x相比,实际应用程序只做了一些微小的更改,总体更改如下:
- 部署在Glassfish 4.1而不是3.1.2.2
- 较新版本的Hibernate
- 更新版本的ActiveMQ(客户端)
我看不到之前的耳朵文件和新的(除了上述的lib-jars),但是当我尝试部署时,我会收到所有EJB的错误:
org.jboss.weld.exceptions.DeploymentException:WELD-001408:注入点时具有限定符@Default
的类型SomethingLogic的不满足依赖关系[BackedAnnotatedField] @Inject private com.my.application.se rver.service.SomethingServiceSession.somethingLogic
其中SomethingService是一个EJB,SomethingLogic是一个Spring bean。 p>
我的EJB定义如下:
@Stateless
@RolesAllowed(secure)
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class SomethingServiceSession实现SomethingService {
@Inject
private SomethingLogic somethingLogic; // Spring bean
SomethingLogic是一个界面。
我有一个beanRefContext.xml包含:
< beans xmlns =http ://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http:/ /www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\">
< bean id =beanFactoryclass =org.springframework.context.support.ClassPathXmlApplicationContext>
< constructor-arg value =classpath *:applicationContext-glassfish.xml/>
< / bean>
< / beans>
EJB服务在glassfish-ejb-jar.xml中定义,如下所示:
< ejb>
< ejb-name> SomethingServiceSession< / ejb-name>
< ior-security-config>
< as-context>
< auth-method> USERNAME_PASSWORD< / auth-method>
< realm> AD< / realm>
< required> true< / required>
< / as-context>
< / ior-security-config>
< / ejb>
我尝试将以下内容的beans.xml添加到resources\META-INF文件夹我的EJB项目:
<?xml version =1.0?>
< beans xmlns =http://java.sun.com/xml/ns/javaeexmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd/>
没有运气。
我也有尝试为所有的EJB添加@LocalBean,也没有运气。
此外,我已经尝试使用以下命令禁用CDI:
asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi = false
这实际上允许我的EJB服务被部署,但我怀疑它没有发现我的网络服务没有那么好的副作用,所以我希望能够部署CDI,以便进行排除。
更新:
我有尝试在所有非Spring处理的类(EJB,Webservices和servlet)中使用@Autowired更改@Inject。现在我对于实际的Spring bean也有同样的错误。看来,Glassfish在遇到@Inject时会尝试寻找EJB bean,无论他们在哪里发生。
修正了我的问题通过向我的各种beans.xml文件添加 bean-discovery-mode =none
。
<?xml version =1.0?>
< beans xmlns =http://java.sun.com/xml/ns/javaeexmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_2.xsd
bean-discovery-mode =none />
I am upgrading an application from Java7 on Glassfish 3.1.2.2, to Java8 on Glassfish 4.1. The application is packaged as an ear file, containing a jar-file with remote EJBs and Spring beans, as well as a war-file with a couple of servlets and some webservices.
There are only some minor changes done to the actual application, compared to how it was with Glassfish 3.x, the total changes made are:
- Built with Java8 instead of Java7.
- Deployed on Glassfish 4.1 instead of 3.1.2.2
- Newer version of Hibernate
- Newer version of ActiveMQ (client)
I can't see any difference between the previous ear-file and the new one (except the abovementioned lib-jars), but still when I try to deploy I get errors like this for all my EJBs:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type SomethingLogic with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private com.my.application.server.service.SomethingServiceSession.somethingLogic
Where SomethingService is an EJB, SomethingLogic is a Spring bean.
My EJBs are defined like this:
@Stateless
@RolesAllowed("secure")
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class SomethingServiceSession implements SomethingService {
@Inject
private SomethingLogic somethingLogic; //Spring bean
SomethingLogic is an interface.
I have a beanRefContext.xml containing:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="beanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="classpath*:applicationContext-glassfish.xml"/>
</bean>
</beans>
The EJB services are defined in glassfish-ejb-jar.xml, like this:
<ejb>
<ejb-name>SomethingServiceSession</ejb-name>
<ior-security-config>
<as-context>
<auth-method>USERNAME_PASSWORD</auth-method>
<realm>AD</realm>
<required>true</required>
</as-context>
</ior-security-config>
</ejb>
I have tried adding a beans.xml with the following content to the resources\META-INF folder of my EJB-project:
<?xml version="1.0"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd" />
No luck.
I have also tried adding @LocalBean to all my EJBs, also with no luck.
In addition, I have tried to disable CDI all together, using this command:
asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi=false
This actually allows my EJB services to be deployed, but I'm suspecting that it has the not so good side effect of my webservices not being discovered, so I want to be able to deploy with CDI enabled to rule this out.
Update:
I have tried changing @Inject with @Autowired in all my non-Spring-handled classes (EJBs, webservices and servlets). Now I get the same error for actual Spring beans. It seems that Glassfish will try to look for EJB beans when encountering @Inject, no matter where they occur.
Fixed my problem by adding bean-discovery-mode="none"
to my various beans.xml files.
<?xml version="1.0"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_2.xsd"
bean-discovery-mode="none" />
这篇关于Glassfish4 + EJB + Spring,部署失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!