Results 1 to 5 of 5

Thread: Propertyplaceholder not workign with request scope

  1. #1

    Unhappy Propertyplaceholder not workign with request scope

    Hi everyone,
    I need to resolve a strange issue with spring propertyplaceholder. I have a subclass of PropertyPlaceholderConfigurer in which i am setting the location of the properties file to load based on some request parameter. So i want this bean to be created dynamically based on each request. Below is the code:
    Code:
    public class IntegrationPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
    	
    	
    	public IntegrationPropertyPlaceholderConfigurer() {
    		ResourceLoader resourceLoader = new DefaultResourceLoader();
    		Resource resource;
    		HttpServletRequest request=((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
    		if(request.getParameter("areavpath")!= null && request.getParameter("areavpath").contains("SFDC")){
    			resource= resourceLoader.getResource("classpath:com/vmware/cms/integration/properties/SFDC.properties");
    			super.setLocation(resource);
    		//	this.postProcessBeanFactory(context.getBeanFactory());
    		}else if(request.getParameter("areavpath")!= null && request.getParameter("areavpath").contains("MYVMWARE")){
    			resource= resourceLoader.getResource("classpath:com/vmware/cms/integration/properties/MyVMWare.properties");
    			super.setLocation(resource);
    		//	this.postProcessBeanFactory(context.getBeanFactory());
    		}
    	}
    	
    }
    And my spring configuration is
    Code:
    <bean id="PropertyConfigurer"
    			class="com.vmware.cms.integration.utility.IntegrationPropertyPlaceholderConfigurer"
    			lazy-init="true" scope="request">
    			<aop:scoped-proxy />
    </bean>
    I have added a requestcontext listener in my web.xml for using request scoped beans. But when i start my server i still get the error:
    Code:
    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.
    Also the bean is not getting created for each request. It is working like a singleton bean. Please help me out!!! Could not find resolution anywhere !!!

  2. #2

    Default

    Can anybody please help me out!!! i need to resolve this ASAP!

  3. #3

    Default

    Posting the full spring configuration:

    Code:
    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    		<bean id="PropertyConfigurer"
    			class="com.trial.cms.integration.utility.IntegrationPropertyPlaceholderConfigurer"
    			lazy-init="true" scope="request">
    			<aop:scoped-proxy />
    		</bean>
    
    	<bean id="integrationInterceptor" scope="request" lazy-init="true"
    		class="com.trial.cms.integration.interceptors.WorkFlowInterceptor">
    		<aop:scoped-proxy />
    		<property name="preProcessors" value="${preprocessors}" />
    		<property name="postProcessors" value="${postprocessors}" />
    	</bean>
    	
    
    	<bean id="WorkflowController" class="com.trial.cms.integration.controllers.WorkflowIntegrationController"
    		lazy-init="true" scope="request">
    			<aop:scoped-proxy />
    			<property name="workflow" ref="${workflow.name}"/>
    	</bean>
    	
    
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/*.do">WorkflowController</prop>
    			</props>
    		</property>
    		<property name="interceptors">
    			<list>
    				<ref local="integrationInterceptor" />
    			</list>
    		</property>
    	</bean>
    
    	<bean id="sfdcWorkflow" class="com.trial.cms.integration.workflows.SFDCWorkFlow">
    		<property name="deployer" ref="wsDeployer"/>
    	</bean>
    	
    	<bean id="myVMWareWorkflow" class="com.trial.cms.integration.workflows.MyWorkFlow">
    		<property name="deployer" ref="fileDeployer"/>
    	</bean>
    
    	<bean id="wsDeployer" class="com.vmware.cms.integration.deployers.WSDeployer" />
    	<bean id="dbDeployer" class="com.vmware.cms.integration.deployers.DBDeployer" />
    	<bean id="fileDeployer" class="com.vmware.cms.integration.deployers.FileDeployer" />
    
    </beans>

  4. #4

    Default

    Posting my entire spring config:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    		<bean id="PropertyConfigurer"
    			class="com.trial.cms.integration.utility.IntegrationPropertyPlaceholderConfigurer"
    			lazy-init="true" scope="request">
    			<aop:scoped-proxy />
    		</bean>
    
    	<bean id="integrationInterceptor" scope="request" lazy-init="true"
    		class="com.trial.cms.integration.interceptors.WorkFlowInterceptor">
    		<aop:scoped-proxy />
    		<property name="preProcessors" value="${preprocessors}" />
    		<property name="postProcessors" value="${postprocessors}" />
    	</bean>
    	
    
    	<bean id="WorkflowController" class="com.trial.cms.integration.controllers.WorkflowIntegrationController"
    		lazy-init="true" scope="request">
    			<aop:scoped-proxy />
    			<property name="workflow" ref="${workflow.name}"/>
    	</bean>
    	
    
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/*.do">WorkflowController</prop>
    			</props>
    		</property>
    		<property name="interceptors">
    			<list>
    				<ref local="integrationInterceptor" />
    			</list>
    		</property>
    	</bean>
    
    	<bean id="sfdcWorkflow" class="com.trial.cms.integration.workflows.SFDCWorkFlow">
    		<property name="deployer" ref="wsDeployer"/>
    	</bean>
    	
    	<bean id="myWorkflow" class="com.trial.cms.integration.workflows.MyWorkFlow">
    		<property name="deployer" ref="fileDeployer"/>
    	</bean>
    
    	<bean id="wsDeployer" class="com.trial.cms.integration.deployers.WSDeployer" />
    	<bean id="dbDeployer" class="com.trial.cms.integration.deployers.DBDeployer" />
    	<bean id="fileDeployer" class="com.trial.cms.integration.deployers.FileDeployer" />
    
    </beans>

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    What you are doing is dangerous and is something you shouldn't do. You are reconfiguring all your beans on each request (including your singletons) now imagine concurrent requests each changing the configuration...

    Also your placeholder shouldn't be an aop:scoped-proxy as you aren't using it for dependency injection.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •