SpringMVC中有两个xml配置文件:
注:${user.dir}为tomcat下的bin目录,不用定义可以直接使用
使用@Value访问:
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配置文件。
properties文件在spring配置文件xml中定义如下:
注:${user.dir}为tomcat下的bin目录,不用定义可以直接使用
db.properties文件:
使用@Value访问: