我在ruoyiCloud项目中使用动态切换环境进行配置,通过选择spring.profile标签进行动态切换
其中对项目中的yml也进行了配置,通过@spring.profile@,@nacos.server.address@,@nacos.server.namespace@,进行了动态配置
nacos也配置了相应的prod,其中的连接ip全部换成了容器名,ruoyi-mysql ruoyi-redis
当使用mvn clean package -P prod指定打包时服务报错:
nacos参考如下:
pom参考如下:
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.profile>dev</spring.profile>
<nacos.server.address>http://192.168.17.131:8848</nacos.server.address>
<nacos.server.namespace></nacos.server.namespace>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<spring.profile>test</spring.profile>
<nacos.server.address>http://192.168.17.131:8848</nacos.server.address>
<nacos.server.namespace>test</nacos.server.namespace>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profile>prod</spring.profile>
<nacos.server.address>http://192.168.17.131:8848</nacos.server.address>
<nacos.server.namespace>prod</nacos.server.namespace>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
yml参考如下: