SpringBoot 项目配置文件可以放在外部 application-prod.properties application-test.properties application-dev.properties 这三种环境, 生产, 测试, 开发 环境的配置文件放在所在服务器的指定目录下, application.properties 文件不用动, 还是放在项目里. 用于配置 spring.profiles.active
需要对启动类进行改造
@SpringBootApplication
public class SpringbootDemo1Application {
public static void main(String[] args) throws IOException {
SpringApplication app = new SpringApplication(SpringbootDemo1Application.class);
Properties properties = new Properties();
properties.load(new ClassPathResource("application.properties").getInputStream());
properties.load(new FileInputStream(new File("/Users/xxxxx/application-"+ properties.getProperty("spring.profiles.active") +".properties")));
app.setDefaultProperties(properties);
app.run(args);
}
}