学习springCloud杂记
程序员文章站
2022-07-06 21:58:52
...
系统默认的配置文件放置的地方
加载自己的配置文件的方法
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class MyConfigApp {
public static void main(String[] args) {
new SpringApplicationBuilder(MyConfigApp.class)
.properties("spring.config.location=classpath:/abc.properties").run(args);
}
}
属性根据环境来切换,实现方式
配置文件
spring:
profiles: linux
server:
port: 8887
---
spring:
profiles: windows
server:
port: 8888
调用代码
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
@SpringBootApplication
public class MyConfigApp2 {
public static void main(String[] args) {
new SpringApplicationBuilder(MyConfigApp2.class)
.properties("spring.profiles.active=windows").run(args);
}
}