tag:blogger.com,1999:blog-4081042681428327092.post4135514899641008698..comments2023-01-19T02:37:54.495-05:00Comments on The Weekly Give: Spring 3.1 @Profile and @PropertySourceMatt Givneyhttp://www.blogger.com/profile/01367149444779607020noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-4081042681428327092.post-48460183292007325702012-03-08T21:23:02.196-05:002012-03-08T21:23:02.196-05:00Your article help me a lot. I wanted to do what yo...Your article help me a lot. I wanted to do what you have but also use variable replacements inside @Value annotations. To get this working it wasn't obvious how this works but the magic was to include a static Bean definition in each file that uses @PropertySource. I thought it was only needed once somewhere in your app but it appears that you need to define it in each file using @PropertySource so that it gets created prior to the BFPP kicking in. <br /><br /><br />@Configuration<br />@Profile(value="PROD")<br />@PropertySource("classpath:/prod-app.properties")<br />public class ProdEnvConfig {<br /><br /> @Value("${service.message}")<br /> private String serviceMessage;<br /> <br /> @Bean<br /> public EnvBean simpleBean(){<br /> EnvBean bean = new EnvBean(serviceMessage);<br /> return bean;<br /> }<br /><br /> /**<br /> * This is the magic that enables variable replacements in @Value definitions<br /> */<br /> @Bean<br /> public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {<br /> return new PropertySourcesPlaceholderConfigurer();<br /> }<br />}Shane Rowattnoreply@blogger.com