I'm a big fan of Spring 3's Java config integration and I've been using it to load my beans, inject variables from properties files etc.
Prior to Spring 3 I used xml configuration files where I would declare property-placeholder files. These properties were then injected by Spring using the ${xxxx} syntax.
Code:<context:property-placeholder location="classpath*:config/*.properties" /> <bean id="myBean" class="com.example.MyClass"> <property name="myProperty" value="${dummy.property.value}" /> </bean>
While using Maven's profiles I was able to substitute these ${xxx} properties with real values coming from specific files. I had 3 profiles : dev, test and production therefore I could build war files for these 3 environments with a single command line.
Is there such a way to do so and enable Maven properties injection with the Spring 3 java config syntax. Per example how could I inject different values for the following code for different environments?
Maven will not introspect through source code and will not be able to hot replace those properties values from a given file. Is there another way to do so?Code:@Value("#{properties.myProperty}") private String myProperty; @Bean public MyClass myClass() { MyClass myClass = new MyClass(); myClass.setMyProperty(this.myProperty); return myClass; }


Reply With Quote