@PropertySource注解的使用
- @PropeertySource,指定加载配置文件
- 使用@Value映射到具体的java属性
CustomConfig.java
package net.cybclass.sp.aop;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource(value = "classpath:config.properties")
public class CustomConfig {
@Value("${server.host}")
private String host;
@Value("${server.port}")
private int port;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
@Override
public String toString() {
return "CustomConfig{" +
"host='" + host + '\'' +
", port=" + port +
'}';
}
}
config.properties
server.host=128.0.0.1
server.port=8080
VideoOrder.java

验证
