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 [通用日志]

最新文章

  1. ExtJS基础知识总结:自定义日历和ComboBox控件(二)
  2. html规范
  3. MySQL 5.5开启慢查询功能
  4. 数据结构1 线段树查询一个区间的O(log N) 复杂度的证明
  5. 支持高并发的IIS Web服务器常用设置 II
  6. bug_ _java.lang.RuntimeException: Unable to start activity ComponentInfo{包名/类名}
  7. HDOJ/HDU 2565 放大的X(分段思考~)
  8. 【HDOJ】1421 搬寝室
  9. json数据返回
  10. Spark技术内幕:Master基于ZooKeeper的High Availability(HA)源码实现
  11. centos7下安装docker(15.8docker跨主机容器通信总结)
  12. ActiveMQ consumer按顺序处理消息
  13. 学习笔记之Bokeh Data Visualization | DataCamp
  14. 墨刀 vs Axure RP
  15. P4711 「化学」相对分子质量
  16. STL标准库-容器-deque
  17. odex反编译dex异常 Cannot locate boot class path file /system/framework/core.odex
  18. webpack中设置jquery为全局对象
  19. 基于多用户的Oracle数据泵导入导出数据
  20. shell 给未定义的变量设定默认值 ${parameter:-word}

热门文章

  1. 7.5.5编程实例-Bezier曲线曲面绘制
  2. (转)RabbitMQ学习之spring整合发送异步消息(注解实现)
  3. mysql_connect() 不支持 请检查 mysql 模块是否正确加载
  4. Python爬虫3-----浏览器伪装
  5. vim牛逼的code工具: ctags+ cscope
  6. SurgingFunction
  7. javaSE常用的英语单词
  8. Ajax json jquery实现菜单案例
  9. C#中的IEnumerable&lt;T&gt;知识点
  10. 具体解释Redis源代码中的部分高速排序算法(pqsort.c)