一、 网上查到的方式:
直接 @PropertySource加载文件@Value读取属性,
Environment.getProperty()获取属性。
结果发现@Value只能拿到"${ips}",获取不到配置文件里的属性。
@Controller
@PropertySource("classpath:queryScoreIPList.properties")
public class UserController {
@Value("${ips}")
private String ips;
@Autowired
private Environment environment;
public void user() {
System.err.println(ips);
System.err.println(environment.getProperty("ips"));
}
}
二、 其他方式:
两种方式加载配置文件,
@Value正常获取属性,
Environment.getProperty()获取不到属性。
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:queryScoreIPList.properties</value>
</list>
</property>
</bean>
<con