Spring 2.0.x Jersey 2 Request scoped bean

不羁岁月 提交于 2019-12-24 15:22:39

问题


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?

来源:https://stackoverflow.com/questions/36531497/spring-2-0-x-jersey-2-request-scoped-bean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!