Spring启动无法启动嵌入式tomcat

时间:2018-05-01 09:16:33

标签: java spring-boot

我尝试启动第一个Spring启动应用程序。这是一个简单的应用程序,我从https://start.spring.io/下载示例项目,包括Web组件(使用Tomcat和Spring MVC进行全栈Web开发)。

根据教程,我只是实现一个简单的hello服务,我可以访问http://localhost:8080/hello,它将显示" hello"。

应用程序运行良好,没有任何错误,但为什么它没有启动tomcat? 所以我访问http://localhost:8080/hell失败了。 为什么简单的应用程序diid启动tomcat? 谢谢!

控制台

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.12.RELEASE)

2018-05-01 16:55:48.190  INFO 8400 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication on Honda-PC with PID 8400 (C:\HondaFiles\eclipse_ws\springBootSpace\demo\target\classes started by Honda in C:\HondaFiles\eclipse_ws\springBootSpace\demo)
2018-05-01 16:55:48.194  INFO 8400 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2018-05-01 16:55:48.275  INFO 8400 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6366ebe0: startup date [Tue May 01 16:55:48 CST 2018]; root of context hierarchy
2018-05-01 16:55:49.532  INFO 8400 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-01 16:55:49.546  INFO 8400 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.675 seconds (JVM running for 2.086)
2018-05-01 16:55:49.547  INFO 8400 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6366ebe0: startup date [Tue May 01 16:55:48 CST 2018]; root of context hierarchy
2018-05-01 16:55:49.548  INFO 8400 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.12.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>

代码:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
@Configuration
@ComponentScan(basePackages="com.example.demo" , basePackageClasses = DemoApplication.class)
@Component
public class DemoApplication {

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


    @RequestMapping(value="/hello")
    @ResponseBody
    public String hello()
    {
        return "hello world";
    }
}

0 个答案:

没有答案
相关问题