Results 1 to 6 of 6

Thread: Injecting properties to a ApplicationContext at deploy time

  1. #1
    Join Date
    Feb 2012
    Posts
    7

    Default Injecting properties to a ApplicationContext at deploy time

    I have a web application that uses spring mvc and I would like to provide values for the placeholders in my ApplicationContext at deploy time. I don't want them to be baked into the war file. Also, I am looking for something that allows me to specify the values per deployment so that if I run two applications on the same tcServer instance, and those 2 applications happen to use some of the same placeholder names, I can provide each deployment with a different set of values for its placeholders.

    Is there a standard way of handling this ?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Put the properties file on the filesystem and not in the war... Properties files can come from anywhere, I also suggest you take a look at Spring 3.1 with the new profile support and finally you could specify the parameters with -D or in your context file.
    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

  3. #3
    Join Date
    Feb 2012
    Posts
    7

    Default

    Thank you. I suppose I could have a convention that puts some "config" folder on the server class path at startup and then in each application context, I could specify, in the PropertyPlaceholderConfigurer that the properties file is at "classpath:my-application/config.properties" That would give each app its own distinct settings.

    Before I made up my own convention, I wanted to check and see if there is already something in common usage.

    Also, does tcServer support any mechanism to provide settings (or a properties file) directly at deploy time?

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

    Default

    It doesn't have to be on the classpath!... You could even use a placeholder (${config.file.location} for instance) and do something like {$config.file.location}/myapp.properties as a file name..

    Quote Originally Posted by wrmay
    Also, does tcServer support any mechanism to provide settings (or a properties file) directly at deploy time?
    Already answered that..

    Quote Originally Posted by Marten Deinum
    finally you could specify the parameters with -D or in your context file
    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
    Feb 2012
    Posts
    7

    Default

    Sorry for being thick but I don't understand about the -D. Isn't that specified at server start time rather than deploy time ?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Tend to have a tomcat per application so depends on your setup . But indeed it is server start time which for the setup here is deploy time. The only way to do that is to specify them in a properties file and put them in a location from where the PPHC will load it, location could be partially configured through -D.

    A last resort would be to modify the PPHC and retrieve some values from JNDI...
    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

Posting Permissions

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