java - Spring Boot 应用程序 Tomcat 服务器未运行

标签 java spring tomcat

我的 CourseApiApp.java 文件中有以下代码:

package io.myapp.hellospringboot;

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

@SpringBootApplication
public class CourseApiApp {

    public static void main(String[] args) {

        SpringApplication.run(CourseApiApp.class, args);

    }

}

当我按下播放按钮时,我看到以下控制台消息:

main] i.a.hellospringboot.CourseApiApp         : Starting CourseApiApp on johndoe-MacBook-Pro.local with PID 22730 (/Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot/target/classes started by john doe in /Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot)
2017-05-02 21:28:29.454  INFO 22730 --- [           main] i.a.hellospringboot.CourseApiApp         : No active profile set, falling back to default profiles: default
2017-05-02 21:28:29.552  INFO 22730 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy
2017-05-02 21:28:30.838  INFO 22730 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-05-02 21:28:30.917  INFO 22730 --- [           main] i.a.hellospringboot.CourseApiApp         : Started CourseApiApp in 2.122 seconds (JVM running for 2.614)
2017-05-02 21:28:30.919  INFO 22730 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy
2017-05-02 21:28:30.920  INFO 22730 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

更新:这是 POM.xml 文件:

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

还有我的 GreetingController.java 文件:

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    @RequestMapping("/hello/{name}")
      String hello(@PathVariable String name) {
        return "Hello, " + name + "!";
      }

}

最佳答案

根本原因是 Maven 缓存中的损坏 jar。删除 ~/.m2/repository 解决了这个问题。

另一种选择是运行 mvn dependency:purge-local-repository

关于java - Spring Boot 应用程序 Tomcat 服务器未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43750126/

相关文章:

java - 如何在JAVA中使用控制点来合成图像?

java - Api 注释的描述已弃用

java - 如何使用 Spring RestTemplate 将 Riot Api 请求映射到对象

java - Spring Boot 服务静态资源 - sitemap.xml

java - 当我的 REST API 返回 500 HTTP 状态时如何禁用 Tomcat 的 html 错误页面

java - 是否可以将所有 jar 存储在 Tomcat lib 文件夹中?

java - 配置 esapi 缓解 XSS SQLI {GET/POST data} 的完美方法

java - 在数学字符串内的数字中添加逗号

java - 将xml解析为java对象

java - Tomcat、JBoss 和 Glassfish 有什么区别?