@Value注解

SpringMVC中有两个xml配置文件:

1、applicationContext.xml,这个是Spring的主配置文件,包括dao层service层的bean定义或扫描、数据源、事务等的配置信息。

2、xxx-servlet.xml,这个是mvc的配置文件,包括controller层的bean定义或扫描、静态资源访问以及view配置

properties配置文件中的信息定义在applicationContext.xml中,那么在service层使用@Value注解即可访问到,但在Controller层使用@Value注解却不能访问到。

若要在Controller层也使用@Value访问properties配置的话,需要在xxx-servlet.xml中也定义properties配置文件。

	<!-- 加载属性文件 -->
	<context:property-placeholder location="classpath:resource/resource.properties"/>

配置文件:

IMAGE_SERVER_URL=http://111.231.73.14/

控制层使用:‘

	@Value("${IMAGE_SERVER_URL}")
	private String IMAGE_SERVER_URL;
转载于: SpringMVC通过注解@Value获取properties配置


猜你喜欢

转载自blog.csdn.net/qq_20867981/article/details/80068909
今日推荐