spring的placeholder配置

来源:互联网 发布:全球网络卫星电视直播 编辑:程序博客网 时间:2024/05/21 09:01

1、spring 的 web 工程的 web.xml 文件配置

<servlet><servlet-name>dispatchServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 默认情况下就会自动找到这个配置文件 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:/conf/dispatch-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatchServlet</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping>

然后在dispatch配置文件中引入spring bean 的配置文件, 可以防止建立多个 appliacationContext对象


2、@value 注解使用

$ 符号可以使用properties 文件中的属性,# 符号可以引用一个bean对象,如@Value("placeHolder.getProperty('key')")


0 0