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);
}
}