1

I m working with a legacy spring 2.0.6 project integrated with jersey 2.x.

The application context contains some beans like:

<!-- - Application context definition -->
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="propertiesArray">
        <list>
            <bean factory-bean="propertiesHolder" factory-method="asProperties" />
        </list>
    </property>
</bean>
<bean name="propertiesHolder"
    class="com.my.TenantPropertiesHolder" scope="request">
    <aop:scoped-proxy/>
</bean>

<!-- LDAP Repository -->
<bean id="LDAP" class="com.my.LdapRepository">

    <property name="name" value="${LDAP.name}" />
    <property name="providerUrl" value="${LDAP.providerUrl}" />
    <property name="baseQuery" value="${LDAP.baseQuery}" />
    <property name="userCommonName" value="${LDAP.userCommonName}" />
    <property name="userPassword" value="${LDAP.userPassword}" />
</bean>

While in web.xml i have:

 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value> 
       classpath:klas-auth-Context.xml
    </param-value>
 </context-param>
 <listener>
     <listener-class>org.springframework.web.context.request.RequestContextListener          </listener-class>
 </listener>
 <servlet>
     <servlet-name>Secured 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.my</param-value>
     </init-param>
     <init-param>
         <param-name>javax.ws.rs.Application</param-name>
         <param-value>com.my.core.auth.injection.JAXRSConfig</param-value>
     </init-param>     
     <load-on-startup>1</load-on-startup>
  </servlet>

how can i get this to work? how can i recover the ldap bean without spring web context loader listener?

<listener-class>
      org.springframework.web.context.ContextLoaderListener  
</listener-class>

from my rest service?

with context loader listener this was my code inside service:

private static ApplicationContext appContext;

@PostConstruct
public void init() {
    appContext = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
}

what now?

Alex
  • 1,515
  • 2
  • 22
  • 44
  • Have you tried to just use `jersey-spring3` (which uses Spring 3) to see if it is backwards compatible with your app? – Paul Samsotha Apr 11 '16 at 04:57
  • i'm working on it... – Alex Apr 11 '16 at 07:41
  • i'm getting this error: Exception 0 :org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ServiceLocator with qualifiers Default at injection point [UnbackedAnnotatedParameter] Parameter 1 of [UnbackedAnnotatedConstructor] @Inject public org.glassfish.jersey.server.spring.scope.RequestContextFilter(ServiceLocator) – Alex Apr 11 '16 at 08:09
  • Looks like a CDI conflict. Are you using JBoss? If so, were you able to run the Jersey app on it before, without the jersey-spring3? The root of the error is not directly related to adding the jersey-spring3. It's a problem with CDI getting mixed in, where Jersey already a DI framework, but CDI doesn't know that, and it's trying to process the injections. I've never used Jersey with JBoss (or in combination with WELD), so I don't really have much to offer as far as a solution goes. – Paul Samsotha Apr 11 '16 at 10:03
  • jboss with jersey is getting me really mad... yes i'm using wildfly 9.2 – Alex Apr 11 '16 at 10:06
  • Are you actually using CDI anywhere in your application? If not, you can try to disable it. I've never done this, but I know it's possible to disable modules. Maybe something you can look into, if you're not using it. – Paul Samsotha Apr 11 '16 at 10:12
  • i read that is possble but really dangerous... i'n a production environment is not really recommended... – Alex Apr 11 '16 at 10:14
  • Have a look [at this](https://jersey.java.net/documentation/latest/cdi.support.html). I've never used it, but it looks like it _might_ work. It says that it _"supports CDI integration in any CDI-enabled HTTP container."_ – Paul Samsotha Apr 11 '16 at 10:16
  • i have added jersey-weld2-se dependency. The previous exception disappeared but now i have this new one: 16:14:22,927 ERROR [io.undertow.request] (default task-29) UT005023: Exception handling request to /core-sync-api/secured/tenants/kas/ldap/sync: javax.servlet.ServletException: org.jboss.weld.exceptions.IllegalStateException: WELD-001304: More than one context active for scope type javax.enterprise.context.RequestScoped at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:485) – Alex Apr 11 '16 at 14:16
  • I was actually thinking the first dependency in that link. The one you're using is for standalone apps – Paul Samsotha Apr 11 '16 at 14:28
  • ok using jersey-cdi1x and org.springframework.web.context.ContextLoaderListener i get on deployment this excetpion:Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. – Alex Apr 11 '16 at 14:41
  • Have a look at [this example](https://github.com/jersey/jersey/tree/2.22.2/examples/helloworld-spring-webapp) – Paul Samsotha Apr 11 '16 at 14:59
  • yes, thanks i have already downloaded it ... but @Autowired annotation doesn't inject anything. i have just null values – Alex Apr 11 '16 at 15:03
  • I can tell you the example _as is_ works fine in plain servlet container like Tomcat. Try and narrow down the problem. Add the CDI integration module to the example and try to run it on JBoss to see if JBoss is the problem. If it works start adding your beans one by one and see if it's your beans. That's pretty much all the advice I have for you – Paul Samsotha Apr 11 '16 at 15:13
  • really thanks... i will try – Alex Apr 11 '16 at 15:16

0 Answers0