Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: parametrizing db connection on deployment

  1. #1

    Default parametrizing db connection on deployment

    hi

    i have quite a common build scenario: when i develop i use a localhost connection string to connect to a local mysql server. but when i deploy (to ec2 using Spring Cloud Foundry) i want my application to connect to a remote db server, not a local one, with a different db connection string (url, username, pwd, etc').

    so i was wondering, is there a way for me to do it by parameters (possibly VM arguments) in deploy time rather than physically replacing my properties file before every build?

  2. #2

    Default

    There are many ways to do this, but none of them have been standardized quite yet (as of Spring 3.0). This is one of the highly anticipated features coming in Spring 3.1.

  3. #3

    Default

    thank you James. in the meantime, i have managed to use tomcat's environment variables to provide reference to my connection properties file.
    the question is, how do i provide those environment variables to my ec2 tc instance in deploy time?

  4. #4

    Default

    Not knowing about the EC2 environment, that's a tough one. Maybe you could set some failsafe defaults, so when the dev-envrionment Tomcat properties are absent, your application will default to the EC2 settings.

  5. #5

    Default

    i might have solved this issue from within spring configuration, but we'll only test it tomorrow. maybe it's possible to deploy and parametrize using VM arguments? let's see.. i'll keep you posted.

  6. #6

    Default

    Thanks, I'm curious to see how you do it. It's one of the most common requests on the Spring JIRA, hence its inclusion into Spring 3.1.

  7. #7

    Default

    under "Launch a new deployment", what is the "Container Initialization Script" option?

    if there is a possibility to add an environment variable to Tomcat through that script (or another way), it will be very helpful.

  8. #8

    Default

    Hi James, like promised - here is the solution, which is rather simple but took us quite a long time to realize due to some lack of basic documentation on Spring Cloud Foundry.

    First, you should configure Spring to read your VM argument using a property placeholder. for example if you're trying to decide which properties file to load using a VM argument, it will look like this:
    Code:
    <context:property-placeholder location="classpath:app-${my.arg}.properties"/>
    then all that's left is to specify JVM arguments, e.g:
    Code:
    -Dmy.arg=localhost
    on the Cloud Foundry deployment configuration - and you're ready to go.

  9. #9

    Default

    I like it! It's simple, clean, and repeatable. Thanks for posting.

  10. #10

    Default

    yep. i'm trying to do the same now with environment variables (because cloud foundry can't delete JVM Options values from the deployment editor without automatically redeploying the server. bah).

    there is "Container Initialization Script" to run shell scripts prior to initialization of the container, but i haven't even been able to find any documentation about it or figure out what kind of script is it looking for - sh? tcsh? where do i see its running results?

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
  •