Results 1 to 7 of 7

Thread: PropertyResourceConfigurer help

  1. #1

    Default PropertyResourceConfigurer help

    Hi.
    can someone please help me out with this problem.

    I have a virtual tomcat server configuration in which i pass some Paramerters as shown below
    <Server ...>
    ... other properties...

    <Host name="xxx.yyy.com" debug="0" appBase="active_web" unpackWARs="true" autoDeploy="true">

    <Context path="" docBase="active_web" debug="0" loadable="true">
    <Parameter name="xxxProperties" value="some file path" override="false"/>
    </Context>

    </Host>

    What i want to do is to get the value of xxxProperties which will be a file name(Outside the application context ) and then read that file using PropertyResourceConfigurer.

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location" value="file:${xxxProperties}"/></bean>

    At the moment xxxProperties cannot be resolved. This xxxProperties should be in the ServeltContext as an init paramter. What am i doing wrong ?

    I also tried using ServletContextPropertyPlaceholderConfigurer instead of PropertyPlaceholderConfigurer still no luck.

    - thanks in advance.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I would have thought ServletContextPropertyPlaceholderConfigurer would be the one you are looking for. Is it possible to see the configuration you were using the exception you were getting?
    Last edited by karldmoore; Aug 29th, 2007 at 10:54 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default stack traces

    Hi,
    This is the stack trace when using ServletContextPropertyPlaceholderConfigurer

    <bean id="propertyConfigurer" class="org.springframework.web.context.support.Ser vletContextPropertyPlaceholderConfigurer">
    <property name="location" value="file:${xxxProperties}"/>
    </bean>
    From the above config i expect the xxxProperties to be resolved in the Servlet Context as (init parameter ) and then use the value to load the file

    ===Stack Trace==
    org.springframework.beans.factory.BeanInitializati onException: Could not load properties; nested exception is java.io.FileNotFoundException: ${xxxProperties} (No such file or directory)
    Caused by:
    java.io.FileNotFoundException: ${xxxProperties} (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
    at java.io.FileInputStream.<init>(FileInputStream.jav a:66)
    at sun.net.http://www.protocol.file.FileURLConn...ection.java:69)
    at sun.net.http://www.protocol.file.FileURLConn...ction.java:156)
    at org.springframework.core.io.UrlResource.getInputSt ream(UrlResource.java:102)
    at org.springframework.core.io.support.PropertiesLoad erSupport.loadProperties(PropertiesLoaderSupport.j ava:179)
    at org.springframework.core.io.support.PropertiesLoad erSupport.mergeProperties(PropertiesLoaderSupport. java:158)
    at org.springframework.beans.factory.config.PropertyR esourceConfigurer.postProcessBeanFactory(PropertyR esourceConfigurer.java:69)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:416)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:330)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:156)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:246)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:184)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 49)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3212)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:3554)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1141)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:707)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1141)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:316)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:450)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2143)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:463)
    at org.apache.catalina.startup.Catalina.execute(Catal ina.java:350)
    at org.apache.catalina.startup.Catalina.process(Catal ina.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:156)

  4. #4

    Default

    The problem i think is that ServletContext is not used to access the property i am after. Its defaulting to ApplicationContext. I dont understand is why the ServletContext is not setup?

    If i just use the ${xxxProperties} then it should find this in the servletContext but it cant for some reaon

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I think the problem here is that you are trying to replace a property in the PropertyPlaceholderConfigurer which is required when loading it. Therefore you are trying to replace a property on the bean using the bean. Wouldn't you need two PropertyPlaceholderConfigurer's? One to load the initial value and replace the location in the second.
    Last edited by karldmoore; Aug 29th, 2007 at 10:54 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  6. #6

    Default

    Quote Originally Posted by karldmoore View Post
    I think the problem here is that you are trying to replace a property in the PropertyPlaceholderConfigurer which is required when loading it. Therefore you are trying to replace a property on the bean using the bean. Wouldn't you need two PropertyPlaceholderConfigurer's? One to load the initial value and replace the location in the second.
    Thanks for the idea.
    i will try that will see how it goes. Now when i think of it , it makes sense using tow PropertyConfigurer and it should work.
    What i will do is have a ServletContextPropertyConfigurer to load the properties i want from the ServletContext.

    And Have another PropertyConfigurer to read the file using the name which just got loaded.

    Thanks

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    You would need to set setIgnoreUnresolvablePlaceholders(true) however to prevent the first one falling over.
    http://www.springframework.org/docs/...lders(boolean)
    Last edited by karldmoore; Aug 29th, 2007 at 10:53 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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