2024年8月10日15:43:40:先不要看,发现还是有点问题,之后学完会了回来修改,抱歉(。・_・。)ノI’m sorry~ ------------------ IDEA2023失败的话尝试application.properties设置为注释,并且尝试新的格式其他不变三个port换为这种#开发 server: port: 86 spring: ,代码如下:
application.yml的:
#设置启用环境
spring:
profiles:
active: ${profile.active}
---
#开发
server:
port: 801
spring:
config:
activate:
on-profile:
---
#生产
server:
port: 802
spring:
config:
activate:
on-profile:
---
#测试
server:
port: 803
spring:
config:
activate:
on-profile:
---
lesson: Springboot
logging:
level:
root: info
enterprise:
name: itcast
age: 16
tel: 12345567867
subject:
- Java
- 前端
- 大数据
接下来是我pom.xml的设置:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.itheima</groupId>
<artifactId>springboot_05_maven_and_boot_profile</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot_05_maven_and_boot_profile</name>
<description>springboot_05_maven_and_boot_profile</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.6.13</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.itheima.Springboot05MavenAndBootProfileApplication</mainClass>
<skip>false</skip>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
<useDefaultDelimiters>true</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<!-- 开发环境-->
<profile>
<id>dev</id>
<properties>
<profile.active>dev</profile.active>
</properties>
</profile>
<profile>
<id>pro</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.active>pro</profile.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profile.active>test</profile.active>
</properties>
</profile>
</profiles>
</project>
经过查找是因为:
<activation>
<activeByDefault>true</activeByDefault>
</activation>
这里默认application.properties被创建了,需要自己创建一个然后随便写点什么给他注释掉才能成功通过pom.xml指向要调用application.yml里面写好的几个端口的哪个端口,还有就是要使用新格式:
server:
port: 801
spring:
config:
activate:
on-profile: