方式1
<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
</bean>
<!-- spring上下文(XML和注解)中的属性占位符替换 -->
<context:property-placeholder properties-ref="properties" trim-values="true"/>
方式2:
<context:property-placeholder location=""xx />
方式3:
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name ="location" value="xxx">
</bean>
方式4:
Any ${...} placeholders present in a @PropertySource resource location will be resolved against the set of property sources already registered against the environment. For example:
@Configuration
@PropertySource("classpath:/com/${my.placeholder:default/path}/app.properties")
public class AppConfig {
@Autowired
Environment env;
@Bean
public TestBean testBean() {
TestBean testBean = new TestBean();
testBean.setName(env.getProperty("testbean.name"));
return testBean;
}
}