Spring 2.0.x Jersey 2 Request scoped bean

2019-08-12 17:57发布

问题:

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?