SpringBootApplication无法解析为某种类型

时间:2016-12-08 05:34:28

标签: spring-boot pom.xml

下面是我的Spring代码和pom.xml。即使我试图强制进行项目更新,Maven也无法更新。关于这个或方向的任何决议我都会出错。

package com.boot;

import org.springframework.*;

@SpringBootApplication
public class App 
{
   public static void main( String[] args )
   {
      System.out.println("Hello World");
   }
}

POM

<groupId>com.boot</groupId>
<artifactId>das-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

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

<name>das-boot</name>
<url>http://maven.apache.org</url>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <start-class>com.boot.App</start-class>
</properties>

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
 </dependencies>
</project>

我不知道为什么Maven无法获得我的项目的依赖项。甲

3 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。
我将版本从2.0.5.RELEASE更改为2.0.3.RELEASE以使其工作

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

答案 1 :(得分:0)

如果可以使用2.x,请按照以下步骤操作:

步骤1 复制到pom下面

<?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>com.boot</groupId>
    <artifactId>das-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>das-boot</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

第2步:这是您的主要应用程序类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DasBootApplication {

    public static void main(String[] args) {
        SpringApplication.run(DasBootApplication.class, args);
    }
}

或者您也可以继续使用1.4.2,只需将Java版本更改为1.6

答案 2 :(得分:0)

您应该在run()方法中提供类名,如下所示:

@SpringBootApplication
public static void main(String[] args) { 
    SpringApplication.run(App.class, args);
    Sytem.out.print("Started");
}

然后从pom.xml中删除以下行

<start-class>com.boot.App</start-class>