【问题标题】:Spring Application cannot be resolved to a typeSpring Application 无法解析为类型
【发布时间】:2019-04-10 07:51:59
【问题描述】:

我正在使用 spring 试验 java Rest 服务。我基本上遵循本指南:https://spring.io/guides/gs/rest-service/
一切都按照教程进行了,但我得到以下编译错误:"Application cannot be resolved to a type" when running 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);
    }
}

【问题讨论】:

    标签: java xml spring maven spring-boot


    【解决方案1】:

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

    SpringApplication.run(App.class, args);
    

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

    【讨论】:

    • 哈哈!你认为我应该删除这个问题,因为这很明显吗?或者它仍然可能以某种方式有所帮助?
    • 您可以留下它,如果有帮助,请将答案标记为正确。人们会犯错误,有时并不明显;)
    猜你喜欢
    • 2017-02-17
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多