第一步:写自定义的properties文件
第二步:在springMvc配置文件spring-servlet文件中配置文件属性(必须是springMvc配置文件)
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:config/law-url.properties</value>
</property>
</bean>
注:
- 配置单个文件是<property name="location">
- 配置多个文件是
<property name="locations"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property>
第三步:在controller层需要从配置文件中获取的属性上加注解
@Value("${url}")
private String url;
需要导入的包是
import org.springframework.beans.factory.annotation.Value;