In your configuration you have two PropertySourcesPlaceholderConfigurer. The first one define in the DispatcherServlet using Java @Configuration uses the standard environment to find properties. This means properties from system environment and environment variables as well as an defined @PropertySource.
This is not aware of your MyApps-local.properties file specified in the applicationContext.xml. The second PropertySourcesPlaceholderConfigurer in the xml file is aware of the MyApps-local.properties file but it only post process placeholder in the root application context
bean factory post processors are scoped per application context.
Change you web application context to specify the property source.This will add the properties in the file to your environment
@Configuration
@PropertySource("classpath:MyApps-local.properties")
public class WebConfig{
@Autowired
private Environment env;
@RequestMapping(value = "myProp", method = RequestMethod.GET)
public @ResponseBody String getMyProp(){
return "The prop is:" + env.getProperty("myProp");
}
}
In this case you dont need the PropertySourcesPlacheholder as you can query for he properties from the environment. Then keep your applicationContext.xml as is
It will also work with the PropertySourcesPlaceholder @Bean as it also picks properties from the enviroment. However the abover is clean than below
@Configuration
@PropertySource("classpath:MyApps-local.properties")
public class WebConfig{
@Value("${myProp}")
private String myProp;
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
@RequestMapping(value = "myProp", method = RequestMethod.GET)
public @ResponseBody String getMyProp(){
return "The prop is:" + myProp;
}
}