首先将共用部分提取出来放置在application.yml中
server:
servlet:
context-path: /
spring:
profiles:
active: 8002
datasource:
#引入druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://。。。。。。。。。。。。
username: root
password: root
#mybatis-plush配置
mybatis-plus:
type-aliases-package: 。。。。。。。。。。。。。。
mapper-locations: classpath:/mybatis/mappers/*.xml
configuration:
map-underscore-to-camel-case: true
#引入日志信息
logging:
level:
。。。。。。。。。。。: debug
然后大家聚焦这块
spring:
profiles:
active: 8002
只要是指定了默认是指向吗、那个开发环境
然后yml搞定了,这时候又有一个问题,我配置文件properties也想做环境的切换咋办?下面是我网上找到的解决方法
@Configuration
@PropertySource("classpath:/tcp-${spring.profiles.active}.properties")
public class HostPort {
@Value("${port}")
private int port;
@Value("${ipaddress}")
private String ipAdress;
目前是可行的,具体的加载过程别人写过的,源码我是真的没有勇气去翻了,大家可以看