Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Override server.properties

    Hi

    Is there a way in which I can override the values set in server.properties at request time?

    Specifically, I am looking at defining multiple db configs (test,stage,production) in the server.properties file and want to decide which db to use based on the host URL. Can this be done?

    Thanks

    #2
    You would generally accomplish this using JNDI, where the same JDNI name on a different host refers to a different database configuration. Otherwise, you need a distinct server.properties file, or (probably not worth it) you can use the DataSource.addDynamicDSGenerator API to make all your DataSources dynamic so that you can switch the "dbName" property on the fly, but this is overkill and JNDI-based switching is the common practice.

    Comment


      #3
      Actually, one more option, you could make calls to com.isomorphic.base.Config to modify server.properties settings. If you do this, be sure to do it after the "Init" servlet has run but before any request have come in, by creating a load-on-startup servlet that runs after the "Init" servlet.

      Comment


        #4
        Actually, I am looking at one instance of the app being hit by 3 different URLs and based on that talking to 3 different db. So if i go to test.myapp.com it the same app server uses test db and when I go to stage.myapp.com it uses stage db. Will the calls to the base.Config work in this case?

        Thanks

        Comment


          #5
          You would need to use the JNDI approach (or the dynamic DataSource approach for this). But note that what is usually meant by staging and test environments is *different code* not just switching the target DB.

          Most teams would handle this via JNDI, and those that did not would handle this as an "ant" task to use a different .properties file in the two environments.

          Comment


            #6
            Hi

            Could you please point me to examples of the two approaches - JNDI and dynamic datasource approach?

            Actually we need to have the same app installed at various locations running against different databases, so need a quick way to test the same code against different databases.

            Thanks.

            Comment

            Working...
            X