配置獨立各自的環境
注:如果需要修改環境測試,只需要修改spring: profiles: active: “環境名”
spring: profiles: active: prd --- #開發環境配置------------------------- server: port: 8081 spring: profiles: dev datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/kyx?useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: root #------------------ --- #測試環境配置 server: port: 8082 spring: profiles: test datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/kyx?useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: root #------------------ --- #生產環境 server: port: 8083 spring: profiles: prd datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/kyx?useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: root #------------------ mybatis: config-location: classpath:/static/mybatis-config.xml mapper-locations: classpath:/mappers/*.xml type-aliases-package: com.example.demo.model
pom依賴
<profiles>
<!--開發環境-->
<profile>
<id>dev</id>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!--測試環境-->
<profile>
<id>test</id>
<properties>
<build.profile.id>test</build.profile.id>
</properties>
</profile>
<!--生產環境-->
<profile>
<id>prd</id>
<properties>
<build.profile.id>prd</build.profile.id>
</properties>
</profile>
</profiles>
配置統一端口
spring: profiles: active: prd server: port: 8081 --- #開發環境配置------------------------- spring: profiles: dev datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/kyx?useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: root #------------------ --- #測試環境配置 spring: profiles: test datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/kyx?useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: root #------------------ --- #生產環境 spring: profiles: prd datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/kyx?useSSL=false&useUnicode=true&characterEncoding=UTF-8 username: root password: root #------------------ mybatis: config-location: classpath:/static/mybatis-config.xml mapper-locations: classpath:/mappers/*.xml type-aliases-package: com.example.demo.model
