1    在 Eclipse 中建立新的web项目【ABC】,之后 转成Maven项目。

2   创建 class   Application

3  修改POM

4  修改web.xml

5  export 成 WAR 到Tomcat 的 workapps里

     6 运行tomcat, 并在浏览器中查看。

Application.class

package demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
private static Class<Application> applicationClass = Application.class; @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
} public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
} } @RestController
class GreetingController { @RequestMapping("/hello/{name}")
String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
}

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.</modelVersion> <artifactId>spring-boot-web-thymeleaf</artifactId>
<packaging>war</packaging>
<name>Spring Boot Web Thymeleaf Example</name>
<description>Spring Boot Web Thymeleaf Example</description>
<url>https://www.mkyong.com</url>
<version>1.0</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4..RELEASE</version>
</parent> <properties>
<java.version>1.8</java.version>
</properties> <dependencies> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> <!-- hot swapping, disable cache for template, enable live reload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency> <!-- Optional, for bootstrap -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.</version>
</dependency> <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency> <dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.1..RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>ABC</display-name>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>demo.Application</param-value>
</context-param> <listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup></load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

查看:  http://localhost:8080/ABC/hello/s

输出 : Hello, s!

参考url:  https://www.cnblogs.com/weixliu/p/6432342.html

备注:

spring-boot-starter-parent [Maven的用户可以通过继承spring-boot-starter-parent项目来获得一些合理的默认配置]
spring-boot-legacy [支持 旧的遗留的 ]
spring-boot-starter-thymeleaf [parse html]
spring-boot-maven-plugin [Java -jar命令来启动jar包,打的包里面才会有maven依赖的jar包和spring boot的启动类]
maven-surefire-plugin [surefire 插件用来在maven构建生命周期的test phase执行一个应用的单元测试]
org.webjars [WebJars能使Maven的依赖管理支持OSS的JavaScript库/CSS库,比如jQuery、Bootstrap等]
spring-boot-devtools [spring-boot-devtools模块可以包含在任何项目中,它可以节省大量的时间] https://blog.csdn.net/isea533/article/details/70495714
commons-logging [通用日志]

deploy springboot to tomcat的更多相关文章

  1. Jenkins deploy war to tomcat over https

    ssl - HTTPS login with Spring Security redirects to HTTP - Stack Overflow https://stackoverflow.com/ ...

  2. SpringBoot切换Tomcat容器,SpringBoot使用Jetty容器

    SpringBoot切换Tomcat容器, SpringBoot修改为Jetty容器, SpringBoot使用undertow容器, SpringBoot使用Jetty容器 ============ ...

  3. SpringBoot系列六:SpringBoot整合Tomcat

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合 Tomcat 2.背景 SpringBoot 本身支持有两类的 WEB 容器:默认的 To ...

  4. Springboot use tomcat JNDI

    Springboot use tomcat JNDI [use database pool :  dbcp Druid bonecp C3P0 proxool] [1]apache-tomcat-9. ...

  5. SpringBoot 配置 Tomcat SSL

    SpringBoot 配置 Tomcat SSL SSL(Secure Sockets Layer , 安全套接层)是为网络通信提供安全及数据完整性的一种安全协议,SSL在网络传输层对网络连接进行加密 ...

  6. Springboot以Tomcat为容器实现http重定向到https的两种方式

    1 简介 本文将介绍在Springboot中如何通过代码实现Http到Https的重定向,本文仅讲解Tomcat作为容器的情况,其它容器将在以后一一道来. 建议阅读之前的相关文章: (1) Sprin ...

  7. spring-boot+nginx+tomcat+ssl配置笔记

    如果你的tomcat应用需要采用ssl来加强安全性,一种做法是把tomcat配置为支持ssl,另一种做法是用nginx反向代理tomcat,然后把nginx配置为https访问,并且nginx与tom ...

  8. SpringBoot启动tomcat源码解读

    一.SpringBoot自动拉起Tomcat 原文链接:http://www.studyshare.cn/blog-front/blog/details/1136 SpringBoot框架是当前比较流 ...

  9. springboot 通过 tomcat 部署的配置

    spring-boot 有一个主类,是可以直接 run,然后就可以访问了,但是如果我们想像传统的那种 web 项目一样部署在 tomcat 里,要怎么配置呢.我们一起来看下. pom.xml 里添加如 ...

随机推荐

  1. (转)基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览

    http://www.cnblogs.com/wuhuacong/p/3871991.html 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览 在博客园很多文章 ...

  2. JDBCUtils 工具类

    import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSource;import java.io.IOE ...

  3. 企业级任务调度框架Quartz(6) 任务调度器(Scheduler)

    前序:      我们已经在前面的内容能里看到了,我们用 Scheduler 来管理我们的 Job:创建并关联触发器以使 Job 能被触发执行:以及如可选择 calendar 为给定的时程安排提供更多 ...

  4. PHP SPL 文件处理(SplFileInfo和SplFileObject)

    SplFileInfo用来获取文件详细信息.SplFileObject遍历.查找指定行.写入csv文件等内容 SplFileInfo用来获取文件详细信息: $file = new SplFileInf ...

  5. 《Python数据分析与挖掘实战》-第四章-数据预处理

    点我看原版

  6. tsar源码分析

    从modules/mod_cpu.c入手 ./devel/tsar.h module 结构体: struct module { char name[LEN_32]; char opt_line[LEN ...

  7. luogu 3768 简单的数学题 (莫比乌斯反演+杜教筛)

    题目大意:略 洛谷传送门 杜教筛入门题? 以下都是常规套路的变形,不再过多解释 $\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{N}ijgcd(i,j)$ $\sum ...

  8. [51nod1074] 约瑟夫问题 V2

    毫无思路,Orz了一下大佬的思路%%%. 大概就是因为k比n小的多,我们知道约瑟夫环有个公式是fn=(fn-1+k) mod n 可以改一下,改成fn+p=(fn+pk) mod (n+p) 但是这样 ...

  9. Problem 7

    Problem 7 # Problem_7.py """ By listing the first six prime numbers: 2, 3, 5, 7, 11, ...

  10. python 协程 greenlet gevent

    一.并发的本质 切换+保存状态 cpu正在运行一个任务,会在两种情况下切走去执行其他的任务(切换由操作系统强制控制),一种情况是该任务发生了阻塞,另外一种情况是该任务计算的时间过长时间片到了 二.协程 ...