1

I am currently dealing with the deployment of my web-server which is why I am facing a presumably very common problem: Configuration files

As a very straight forward example let's take a database. I have a local database.xml which contains the data source which I use on my local machine:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:postgresql://localhost:5432/mz_db" />
    <property name="username" value="postgres" />
    <property name="password" value="pg" />
</bean>

but of course, I am connecting to a different database once I deploy the server. So what are my options here? I would like to have this as centralized as possible to prevent wrong files being deployed here. I am sure that maven can be used for this somehow.

I was thinking about doing something like creating two config/ directories

WEB-INF/config/
WEB-INF/config-dev/

and use config-dev/ per default without the exception of the deploy phase or something like this. I am not sure if this can be done or if this is the best way of doing it.

Any suggestions?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • 1
    rule in general keep configuration out of application. which application server are you using? – Hisham Khalil Jun 02 '16 at 14:10
  • @Hishamkh I am not sure if I understand. What do you mean with "*keep configuration out of application*"? I am using Spring which comes with quite some `applicatoinContext-*.xml` stuff and there's stuff like the database connection defined like you see it in my question. Not sure what to answer by application server :D I am using Tomcat currently but I might have to switch to Jetty. – Stefan Falk Jun 02 '16 at 18:45
  • You can use [external propery files](http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html). Checkout this [stackoverflow thread](http://stackoverflow.com/questions/8270290/spring-application-context-external-properties) – mac Jun 03 '16 at 05:54
  • you can take a look here: https://github.com/khmarbaise/multienv-maven-plugin that removes the need for profiles and produces packages for each environment in one go... – khmarbaise Jun 03 '16 at 06:13
  • @khmarbaise Looks promising! I'll take a look. Thanks :) – Stefan Falk Jun 03 '16 at 07:43
  • @mac That's not really what I need here. All configuration files are always at the same place. No matter where the server is actually running. The my problem is more packaging related. Thank you anyway :) – Stefan Falk Jun 03 '16 at 07:47
  • @khmarbaise How does such a `*.properties` look like? O_o – Stefan Falk Jun 03 '16 at 13:11
  • @displayname What do you mean? – khmarbaise Jun 03 '16 at 13:12
  • @khmarbaise I don't understand how these `.properties` files have to look like. How can I define certain files which I want to use for certain environments etc. – Stefan Falk Jun 03 '16 at 13:14
  • You can put different files (and of course different file types) into the appropriate folders and they will be packaged into a the resulting archive. It is not limited to `.properties` you can use any kind of file...Those property files are only given as an example... – khmarbaise Jun 03 '16 at 13:24

0 Answers0