81,094
社区成员
发帖
与我相关
我的任务
分享
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- 允许JVM参数覆盖 -->
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<!-- 忽略没有找到的资源文件 -->
<property name="ignoreResourceNotFound" value="true" />
<!-- 配置资源文件 -->
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:shield.properties</value>
<value>classpath:mail.properties</value>
</list>
</property>
</bean>
@Component
public class ConfigProperties {
@Value("#{configProperties['shieldTime']}")
private long shieldTime;
@Value("#{configProperties['workState']}")
private int workState;
@Value("#{configProperties['host']}")
private String host;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getMailChecker() {
return mailChecker;
}
@RequestMapping(value = "/mail",method = RequestMethod.POST)
public @ResponseBody BaseResult<String> sendMail(@Valid SendMailInfo info){
ConfigProperties p=new ConfigProperties();
LOGGER.info(p.getHost());
LOGGER.info(""+p.getShieldTime());}
@Autowired ConfigProperties p;
注入变量类的做法我也试过了,还是不行,虽然知道是容器问题但,原理上不太懂还是搞不定