1. 程式人生 > >利用Maven構建SpringBoot專案時@SpringBootApplication無法解析為型別

利用Maven構建SpringBoot專案時@SpringBootApplication無法解析為型別

 問題應該出在pom.xml檔案中,就是下面這段配置中的版本不對

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.5.RELEASE</version>
    </parent>

將<version>1.1.5.RELEASE</version>

改為<version>1.5.8.RELEASE</version>

然後編譯pom檔案,@SpringBootApplication就成功解析了

最後附上我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>org.springframework</groupId>
    <artifactId>gs-rest-service</artifactId>
    <version>0.1.0</version>
 
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>
 
  <dependencies>
     <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
     </dependency>
     <dependency>
           <groupId>org.junit.jupiter</groupId>
           <artifactId>junit-jupiter-api</artifactId>
           <version>5.0.3</version>
           <scope>test</scope>
     </dependency>
  </dependencies>
 
</project>