Results 1 to 7 of 7

Thread: Can one use .properties variables in web.xml file?

  1. #1
    Join Date
    Apr 2009
    Posts
    14

    Default Can one use .properties variables in web.xml file?

    I have a web application with a PropertyPlaceholderConfigurer that fetches properties from a somefile.properties.

    In web.xml I have:

    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath*:applicationContext*.xml</param-value>
    	</context-param>
    
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>

    I was trying to set up this web.xml element:
    Code:
    	<session-config>
    		<session-timeout>${some.property}</session-timeout>
    	</session-config>
    where some.property is in my somefile.properties. However, this doesn't resolve. My question is: is it possible to use placeholder properties in web.xml ? If so, how?

    Thank you for the help!

  2. #2
    Join Date
    May 2011
    Location
    delhi
    Posts
    10

    Default

    this post will help you resolve your problem
    http://stackoverflow.com/questions/2...ith-contextcon

  3. #3
    Join Date
    Apr 2009
    Posts
    14

    Default

    Quote Originally Posted by vishnu.joshi View Post
    this post will help you resolve your problem
    http://stackoverflow.com/questions/2...ith-contextcon
    I don't think it's the same. That link talks about "defining which properties file to use in web.xml", not about setting web.xml elements to values defined in a properties file.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    It isn't possible, spring will only use the properties to replace values in applicationcontexts not in other files.
    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

  5. #5
    Join Date
    May 2011
    Location
    delhi
    Posts
    10

    Default

    Yes you are right its not the same. If you want to access the values of a property file in web.xml then i think it won't be possible. As the app server or web server reads the web.xml and they provide no such support.

    If you want to set the session timeout using property file then a work around could be using a HttpSessionListener. In the sessionCreated() method, you can set the session timeout using your property file value.

  6. #6
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    I suggest using a listener to set the session timeout (or other j2ee properties) programmatically reading the values from a properties file at the start of the application.

  7. #7
    Join Date
    May 2011
    Posts
    2

    Default

    Hi vishnu.joshi. Thank for sharing link. It helps me, too.
    Right message at right time will always be perfect and harmonious. seo companies

Posting Permissions

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