属性文件在controller层中的应用

设置一个env.properties文件后,如果在service中应用,则

@Repository
@Value("${image_url}") //属性名为image_url private String IMAGE_URL;

在applicationContext.xml配置文件中添加其属性文件

<context:property-placeholder location="classpath:*.properties"/>

如果在controller层中应用,由于controller层加载时spring配置文件还未加载,所以不能直接使用,需要额外在springmvc-servlet.xml配置属性文件

<context:property-placeholder location="classpath:env.properties"/>

然后再controller中像以上一样的方法使用

posted @ 2019-10-13 19:58  森罗的灵峰  阅读(110)  评论(0编辑  收藏  举报