config.properties
server.key111=assign-center
location.path=d:/bjdata
target.path=d:/bjdata
spring-*.xml配置
<!--扫描和properties配置一定要在一个xml里,否则可能会读取不到,这里涉及到一个xml作用域的问题-->
<context:component-scan base-package="com.porm.assign.config"/>
<context:property-placeholder location="classpath:assign_config/config.properties" ignore-unresolvable="true"/>
java 文件,如果设置了初始值,也是以配置文件为准
@Component
public class AssignConfig {
@Value("${location.path}")
private String fileLocation="hehe";
@Value("${target.path}")
private String fileTargetPath;
@Value("${server.key111}")
private String serverKey;
public String getFileLocation() {
return fileLocation;
}
public String getFileTargetPath() {
return fileTargetPath;
}
public String getServerKey() {
return serverKey;
}
}