首页>代码>Spring Boot配置@Profile注解加载不同环境的配置文件实例>/profiles/src/main/java/com/memorynotfound/springboot/Application.java
package com.memorynotfound.springboot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import javax.annotation.PostConstruct; @SpringBootApplication @EnableConfigurationProperties(ApplicationProperties.class) public class Application { private static Logger logger = LoggerFactory.getLogger(Application.class); @Autowired private ApplicationProperties properties; @Autowired private Configuration configuration; public static void main(String... args) throws Exception { SpringApplication.run(Application.class, args); } @PostConstruct private void init(){ logger.info("Spring Boot - active profile: " + configuration.getName()); logger.info("Spring Boot - Choosing Your Profile and @Profile annotation example"); logger.info(properties.toString()); } }