1

I have just taken on this project and its in an interesting state. I am trying to establish a local, dev, and production environment. I have it working and was curious to know if there is a better way or if the way I am doing it has risks.

Inside my Dispacher-Servlet.xml i have this line:
<context:property-placeholder location="classpath:application_${spring.profiles.active}.properties" />

Then I have a setenv.sh file that uses:
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=local"

Then inside of my controller to reference the variables I use:
@PropertySource("classpath:application_${spring.profiles.active}.properties")

Like I said it seems to work ok, it just doesn't seem to be what the documentation points you to do.

B Rad
  • 571
  • 3
  • 9
  • 28
  • 1
    @B Rad, did you consider using Spring Profiles? here's a few other suggestions http://stackoverflow.com/questions/9470551/spring-property-substitution-for-test-and-production – AtomHeartFather Apr 06 '15 at 18:40
  • Oh, and there are ``maven`` profiles as well, which may be worth looking into if you're already using maven – AtomHeartFather Apr 06 '15 at 18:41
  • I looked into profiles however it looked like I would need to duplicate a lot of the settings inside the dispatcher. I had 3 different `beans` with different profile names but I couldn't figure out how to have a bean they all could share. It seemed overly complex for what I was looking for. The biggest problem with that approach was I couldn't figure out how to us it inside a controller. – B Rad Apr 06 '15 at 18:45
  • Are you packaging all your environment properties file within the ear/war? – zoostar Apr 06 '15 at 18:55
  • I have 5 different property files within the Resources directory. I do not have a war directory in this project. The structure of this project is foreign to me. – B Rad Apr 06 '15 at 19:12

0 Answers0