标签:database location cat not void 简单 list oca port
import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; @Configuration public class Config { @Value("${test}") private String test; public String getTest() { return test; } }
2.Spring配置
<!-- 获取配置属性值 --> <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:app/env/config.properties</value> <value>classpath:app/config/database.properties</value> <value>classpath:app/config/redis.properties</value> </list> </property> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="properties" ref="configProperties" /> </bean>
3.测试接口类
@Service public class SsoInterface { @Autowired private SsoConfig SsoConfig; public void test(){ System.out.println(SsoConfig.getTest()); } }
最后就能输出 需要的配置文件对应信息
读取properties的简单方法,使用@Configuration
标签:database location cat not void 简单 list oca port
原文地址:http://www.cnblogs.com/wdhwzm/p/7682953.html