1

I develop a rest WS that will run on AWS BeanStalk.

For the moment, the datasource is configured with property files:

database.driverClass=org.postgresql.Driver
database.jdbcUrl=jdbc:postgresql://localhost:5432/public
database.username=postgres
database.password=postgres

And in context.xml:

<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <property name="driverClass" value="${database.driverClass}" />
    <property name="jdbcUrl" value="${database.jdbcUrl}"/>
....

But now, I need to have a preprod environnement, using AWS Beanstalk, that expose my system properties like RDS_HOSTNAME, RDS_PORT, RDS_DB_NAME, ...

Is there a way to keep the same system, like writing

database.jdbcUrl=jdbc:postgresql://#{RDS_HOSTNAME}:#{RDS_PORT}/#{RDS_DB_NAME}

In preprod.property?

Or to reset database.jdbcUrl with system property in context.xml?

farvilain
  • 2,552
  • 2
  • 13
  • 24
  • Would setting the properties on the command line work? – chrylis -cautiouslyoptimistic- Mar 17 '14 at 14:17
  • What build tools are you using? It would be simple enough to write a script to generate a custom properties file based on an output goal. – mttdbrd Mar 17 '14 at 14:37
  • @mttdbrd : I prefer to have a single war that loads his context dependending on spring.profiles.active. – farvilain Mar 17 '14 at 14:46
  • @chrylis : I see with your comment and mttdbrd's one that I forgot to say it's a webapp :p – farvilain Mar 17 '14 at 14:47
  • Yes, I'm saying you make a goal for say Maven like "preprod" and it automatically creates the correct properties file and stuffs it in the single war. If used properly, a single build tool could generate the correct war file with the correct .properties for test, local, preprod, prod, etc. – mttdbrd Mar 17 '14 at 14:54
  • Also, check this thread out: http://stackoverflow.com/questions/7671871/configuring-system-property-in-spring?rq=1 – mttdbrd Mar 17 '14 at 14:56

1 Answers1

4

You could do

   <context:property-placeholder ignore-unresolvable="true" ignore-resource-not-found="true" location="classpath:database.properties, file:preProd.properties" />

And preProd.properties will be on the preprod machine. The keys will be the same but the values will be different. This way if preProd.properties is not found (on dev machine for example) the database.properties will be used. If the file preProd.properties is present it will override the values from database.properties.

If you are using maven you could also use maven profile and maven-replacer-plugin.

harschware
  • 13,006
  • 17
  • 55
  • 87
sergiu
  • 389
  • 1
  • 7
  • Maven seems to be the way to go here. Not sure if OP is using it but this is the kind of problem Maven was designed to solve. I'm sure you could do the same thing with Gradle but I don't know how. – mttdbrd Mar 17 '14 at 14:58
  • It's not applicable cause the goal is to deploy on beanstalk, that creates a RDS and gives us system property. The ops only wants to deploy a war file without any build system. – farvilain Mar 17 '14 at 16:08
  • How did they get the war file? You had to do some kind of build to get to that point. All I'm saying is intervene right before everything is packaged up. – mttdbrd Mar 17 '14 at 16:24