檢查之后發現是依賴的問題(之前依賴的是 spring-boot-starter),修改即可:
pom.xml加上下面兩個依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
加完后: