deploy springboot to tomcat
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的更多相关文章
- Jenkins deploy war to tomcat over https
ssl - HTTPS login with Spring Security redirects to HTTP - Stack Overflow https://stackoverflow.com/ ...
- SpringBoot切换Tomcat容器,SpringBoot使用Jetty容器
SpringBoot切换Tomcat容器, SpringBoot修改为Jetty容器, SpringBoot使用undertow容器, SpringBoot使用Jetty容器 ============ ...
- SpringBoot系列六:SpringBoot整合Tomcat
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合 Tomcat 2.背景 SpringBoot 本身支持有两类的 WEB 容器:默认的 To ...
- Springboot use tomcat JNDI
Springboot use tomcat JNDI [use database pool : dbcp Druid bonecp C3P0 proxool] [1]apache-tomcat-9. ...
- SpringBoot 配置 Tomcat SSL
SpringBoot 配置 Tomcat SSL SSL(Secure Sockets Layer , 安全套接层)是为网络通信提供安全及数据完整性的一种安全协议,SSL在网络传输层对网络连接进行加密 ...
- Springboot以Tomcat为容器实现http重定向到https的两种方式
1 简介 本文将介绍在Springboot中如何通过代码实现Http到Https的重定向,本文仅讲解Tomcat作为容器的情况,其它容器将在以后一一道来. 建议阅读之前的相关文章: (1) Sprin ...
- spring-boot+nginx+tomcat+ssl配置笔记
如果你的tomcat应用需要采用ssl来加强安全性,一种做法是把tomcat配置为支持ssl,另一种做法是用nginx反向代理tomcat,然后把nginx配置为https访问,并且nginx与tom ...
- SpringBoot启动tomcat源码解读
一.SpringBoot自动拉起Tomcat 原文链接:http://www.studyshare.cn/blog-front/blog/details/1136 SpringBoot框架是当前比较流 ...
- springboot 通过 tomcat 部署的配置
spring-boot 有一个主类,是可以直接 run,然后就可以访问了,但是如果我们想像传统的那种 web 项目一样部署在 tomcat 里,要怎么配置呢.我们一起来看下. pom.xml 里添加如 ...
随机推荐
- 05《UML大战需求分析》之五
调研需求的时候,用户会说这个软件要具备怎样的功能,能做什么事情等,这些是功能性的需求.部署图和构件图是用来描述软件架构的,但是我又怀疑软件需求调研也需要确定软件架构吗? 我阅读了一个例子,一个软件公司 ...
- 图表库 - Highchart / Echart
当前主要使用HighChart和Echart图表库,都基于Jquery,需要先引用Jquery. 实际问题:引入Jquery需在图表库前,否则报错. HighChart官网:https://www.h ...
- ack 工具
ack-tools ack其实就是快速查找工具,但centos在没有这个安装包. 下载安装 cd /tmp git clone https://github.com/dongci/ack.git cd ...
- jq操作table追加td
示例 代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 【CF666E】Forensic Examination - 广义后缀自动机+线段树合并
广义SAM专题的最后一题了……呼 题意: 给出一个长度为$n$的串$S$和$m$个串$T_{1\cdots m}$,给出$q$个询问$l,r,pl,pr$,询问$S[pl\cdots pr]$在$T_ ...
- sessionStorage与clone方法在项目中的应用
//资料列表: //JSON.parse(jsonstr); //json格式字符串转换成json对象 //JSON.stringify(jsonobj); //json对象转换成json格式字符串 ...
- [51nod1074] 约瑟夫问题 V2
毫无思路,Orz了一下大佬的思路%%%. 大概就是因为k比n小的多,我们知道约瑟夫环有个公式是fn=(fn-1+k) mod n 可以改一下,改成fn+p=(fn+pk) mod (n+p) 但是这样 ...
- BJOI2012 最多的方案
BJOI2012 最多的方案 Description 第二关和很出名的斐波那契数列有关,地球上的OIer都知道:F1=1, F2=2, Fi = Fi-1 + Fi-2,每一项都可以称为斐波那契数 ...
- 3.1、Ansible命令简要说明及初步使用
1.Ansible命令 1.1 Ad-hoc说明 Ansible中有一个很重要的功能就是可以执行ad-hoc命令,它表示即时.临时的意思,即表示一次性的命令.与之相对的是ansible playboo ...
- Centos6.5安装Seafile,遇到的问题处理记录。
问题1:启动Seafile安装脚本时,提示找不到MySQL-python模块,使用yum安装成功也提示未安装该软件包 问题1解决方法:需要通过 python 的工具pip来安装MySQL-python ...