我在之前的项目中一直使用下面的格式注入:
@Value("#{config['redis.host']}")
private String redisHost;
使用下面的方式注入总是不成功。
@Value("${redis.host}")
private String redisHost;
最近终于发现,扫描配置文件的语句:
<context:property-placeholder location="classpath*:/xxx.properties" />
要交给springMVC的DispatcherServlet去扫描,而不是spring的监听器ContextLoaderListener去扫描,就可以比较方便的使用“${xxx}”去注入。