Spring Application无法解析为类型

时间:2019-04-10 07:51:59

标签: java spring spring-boot

我正在使用spring尝试Java Rest服务。我基本上遵循此指南:https://spring.io/guides/gs/rest-service/
根据教程,一切都已遵循,但出现以下编译错误:运行"Application cannot be resolved to a type"时出现SpringApplication.run(Application.class, args);
我认为没有明显的原因,因此不胜感激。

以下是相关文件:
pom.xml     

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>2.1.4.RELEASE</version>
     </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-test</artifactId>
       <version>2.1.4.RELEASE</version>
     </dependency>
     <dependency>
       <groupId>com.jayway.jsonpath</groupId>
       <artifactId>json-path</artifactId>
       <version>2.4.0</version>
     </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
        <plugins>

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

    <plugin>
      <!-- Build an executable JAR -->
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.1.0</version>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>de.debeka.rzm.testingRest.App</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>


        </plugins>
    </build>

GreetingController

@RestController
public class GreetingController {
    private static final String template = "Hello, %s!";

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        return new Greeting(1, String.format(template, name));
    }
}

主要

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

1 个答案:

答案 0 :(得分:4)

您拼错了主类的名称。更改为:

SpringApplication.run(App.class, args);

它应该这样做。您需要提供带有@SpringBootApplication注释的类的名称。