springboot获取配置文件值的几种方式

注解@Value

@Value("${spring.profiles.active}")
private String environment;

@Value("${server.port}")
private int httpPort;

... get set

注入Environment

@Autowired
Environment environment;

environment.getProperty("server.port");

实现EnvironmentAware

重写setEnvironment(Environment environment)方法

Dylan

面朝大海·春暖花开

发表评论