Spring Boot应用程序无法启动Tomcat服务器

时间:2017-11-27 12:32:09

标签: java spring spring-mvc tomcat spring-boot

我正在使用Spring Tool Suite开发一个简单的“Spring启动项目”(spring-boot),它在收到get请求时返回一个字符串。

项目构建成功,但不是启动Tomcat服务器,而是完成执行。

我尝试使用Maven插件从命令行运行它并作为打包的应用程序(jar文件),但结果是相同的。

我是Spring-boot的新手,并试图遵循各种教程并搜索了很多解决方案,但找不到任何东西。这是我的代码和控制台输出:

的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>com.hraichandani</groupId>
    <artifactId>starter-app-2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>starter-app-2</name>
    <description>Spring Boot Starter App</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.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>
        <tomcat.version>8.5.23</tomcat.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <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>

application.java

@SpringBootApplication
@RestController
public class StarterApp2Application {

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

    @RequestMapping(value="/greeting", method=RequestMethod.GET)
    public String sayHello() {
        return "Hello";
    }
}

控制台输出

2017-11-27 04:05:49.881  INFO 17685 --- [           main] com.hraichandani.StarterApp2Application  : Starting StarterApp2Application on Hiteshs-MacBook-Pro.local with PID 17685 (/Users/hitesh/Documents/spring-workspace/starter-app-2/target/classes started by hitesh in /Users/hitesh/Documents/spring-workspace/starter-app-2)
2017-11-27 04:05:49.884  INFO 17685 --- [           main] com.hraichandani.StarterApp2Application  : No active profile set, falling back to default profiles: default
2017-11-27 04:05:49.916  INFO 17685 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@76b10754: startup date [Mon Nov 27 04:05:49 PST 2017]; root of context hierarchy
2017-11-27 04:05:50.838  INFO 17685 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-11-27 04:05:50.842  INFO 17685 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-11-27 04:05:50.891  INFO 17685 --- [           main] com.hraichandani.StarterApp2Application  : Started StarterApp2Application in 11.226 seconds (JVM running for 16.758)
2017-11-27 04:05:50.892  INFO 17685 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@76b10754: startup date [Mon Nov 27 04:05:49 PST 2017]; root of context hierarchy
2017-11-27 04:05:50.895  INFO 17685 --- [       Thread-3] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2017-11-27 04:05:50.897  INFO 17685 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

非常感谢任何帮助。谢谢!

0 个答案:

没有答案