java - spring boot 无法启动嵌入式tomcat
问题描述
我尝试启动第一个 Spring Boot 应用程序。这是一个简单的应用程序,我从https://start.spring.io/下载示例项目,包括 Web 组件(使用 Tomcat 和 Spring MVC 进行全栈 Web 开发)。
根据教程,我只是实现了一个简单的 hello 服务,我可以访问http://localhost:8080/hello,它会显示“hello”。
应用程序运行良好,没有任何错误,但是为什么它没有启动tomcat?所以我访问http://localhost:8080/hell失败了。为什么简单的应用程序没有启动 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
聚甲醛:
<?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";
}
}
解决方案
推荐阅读
- dart - 对不可为空的变量使用 late 关键字有什么好处?
- java - LinkedMultiValueMap SpringFramework 未迭代(错误:无法转换为类)
- database - mysql 连接器在故障转移到从属设备后无法回退到主控设备
- c# - 具有多种不同类型的列表
- javascript - parentNode.removeChild() 和 remove() 有什么区别
- hibernate - 使用 Hibernate/JPA 在 Spring Boot 上的购物车应用程序
- rest - Azure DevOps 问题通过包含德语变音符号的 REST 调用创建项目
- django - Django RadioSelect 小部件,添加附加信息
- php - 带有验证码的 PHP 表单不起作用(白屏)
- angular-calendar - 在不使用 CalendarEvent 的情况下从 Mysql 获取数据到 Angular-Calendar