2
votes

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.

1

1 Answers

2
votes

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" />