1 Reply Latest reply on Oct 12, 2015 2:21 AM by Philippe Marschall

    HK2 Jersey CDI and WELD CDI coexistence

    Alessio Orlando Newbie

      hi to all,

      in my use case i developed a REST service layer for my application running in WildFly 9

      My requirement is to use Jersey 2.x... and this is done. My web.xml looks like this standard:

       

         <servlet>

        <servlet-name>Jersey REST Service</servlet-name>

        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

        <init-param>

        <param-name>jersey.config.server.provider.packages</param-name>

        <param-value>com.mycom.sec.rest</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

        </servlet>

        <servlet-mapping>

        <servlet-name>Jersey REST Service</servlet-name>

        <url-pattern>/rest/*</url-pattern>

        </servlet-mapping>

       

      My Rest services uses DAO built on JPA and would like to use JTA transaction manager.

      I've annotated the service with @Stateless annotation and then with @RequestScoped annotation

       

      @RequestScoped /@Stateless

      @Path("/users")

      public class UserResourceRESTService {

        IMapUserDao mapUserDao = new MapUserDaoKasImpl(dataSourceJNDI);

      @GET

      @Produces(MediaType.APPLICATION_JSON)

      public List<BaseUser> listAllUsers() {

          List<BaseUser> users = null;

          try {

          users = mapUserDao.getAllUsers();

       

      And this the DAO

       

      @RequestScoped /@Stateless

      @TransactionManagement(TransactionManagementType.BEAN)

      @SuppressWarnings("unchecked")

      public class MapUserDaoKasImpl implements IMapUserDao  {

        @Resource

        UserTransaction useTransaction;

       

        EntityManagerFactory factory;

        protected MapUserDaoKasImpl()

        }

        protected MapUserDaoKasImpl(String dataSourceJNDI){

           ....

        }

       

      It seems @Resource annotation is never attached by weld and UserTransaction is alway NULL.

      It seems so tricky to use Jersey inside Wildfly. Why?

      What am i doing wrong?

      Thanks