输出中以下属性的值为null.
package com.project.service.impl;
import org.springframework.beans.factory.annotation.Value
@Service("aService")
@PropertySource(value="classpath:app.properties")
public class ServiceImpl implements Service{
private Environment environment;
@Value("${list.size}")
private Integer list1;
@Value("${list2.size}")
private Integer list2Size;
@Autowired
public ServiceImpl(StringRedisTemplate stringTemplate){
this.stringTemplate = stringTemplate;
logger.info("TESTING 123: "+list1);
}
// ...
}
@EnableWebMvc
@ComponentScan(basePackages = {"com.project.service","..."})
@Configuration
public class ServletConfig extends WebMvcConfigurerAdapter {
// ...
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[] {
new ClassPathResource("app.properties")
};
propertyPlaceholderConfigurer.setLocations(resources);
propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
return propertyPlaceholderConfigurer;
}
}
本文由 投稿者 创作,文章地址:https://blog.isoyu.com/archives/spring-serviceleizhongdevalueshuxingweinull.html
采用知识共享署名4.0 国际许可协议进行许可。除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为:11月 11, 2019 at 09:27 下午