工程目录

pom文件注意点

<packaging>war</packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<build>
<finalName>prs</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>

配置文件application.properties

server.port=
server.session.timeout=
server.context-path=/prs #thymelea模板配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
#spring.resources.chain.strategy.content.enabled=true
#spring.resources.chain.strategy.content.paths=/** # 上传文件大小配置
spring.http.multipart.maxFileSize=10MB
spring.http.multipart.maxRequestSize=10MB #spring.mvc.async.request-timeout=600000
#spring.http.multipart.max-request-size=200MB #spring.aop.auto=true
#spring.aop.proxy-target-class=false #server.tomcat.uri-encoding=UTF-8
#server.tomcat.max-threads=100
logging.config=classpath:logback.xml #mybatis.configLocation=classpath:mybatis/mybatis-config.xml
#mybatis.mapperLocations=classpath:mybatis/mapper/*.xml #spring.datasource.driverClassName = com.mysql.jdbc.Driver
#com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.datasource.url = jdbc:mysql://127.0.0.1:3306/test
#jdbc:sqlserver://104.15.202.101:1105;DatabaseName=tt
#spring.datasource.username = root
#spring.datasource.password = 123456 #spring.datasource.initialSize=2
#spring.datasource.minIdle=0
#spring.datasource.maxActive=5
#spring.datasource.maxWait=60000
#spring.datasource.validationQuery=select 1
#spring.datasource.timeBetweenEvictionRunsMillis=60000
#spring.datasource.testWhileIdle=true
#spring.datasource.testOnBorrow=true
#spring.datasource.testOnReturn=false
#spring.datasource.poolPreparedStatements=true
#spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
server.context-path=/prs这里的路径名最好和上面pom里的finalName最好是一致的,因为当我们把打包好的war包放到tomcat的webapp里时,访问路径前缀就是这个finalName

启动类

@ComponentScan(basePackages= {"com.wymessi"})//扫描组件
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableTransactionManagement(proxyTargetClass = true)
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class})
public class SpringbootApplication extends SpringBootServletInitializer { public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
} @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// 注意这里要指向原先用main方法执行的Application启动类
return builder.sources(SpringbootApplication.class);
} // @Bean
// public HttpMessageConverters fastJsonHttpMessageConverters() {
// FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
// FastJsonConfig fastJsonConfig = new FastJsonConfig();
// // fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserCompatible);
// // fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserSecure);
// fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
// // fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
// SerializeConfig config = new SerializeConfig();
// config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
// fastJsonConfig.setSerializeConfig(config);
// fastConverter.setFastJsonConfig(fastJsonConfig);
// HttpMessageConverter<?> converter = fastConverter;
// return new HttpMessageConverters(converter);
// } }

和打jar包的区别是继承了SpringBootServletInitializer这个类,然后重写了configure方法。

运行程序

eclipse里运行

右击项目名,run as - spring boot app。

浏览器里输入http://127.0.0.1:8013/prs

打包成war包在tomcat里运行

右击项目名,run as - maven - build,看到success就代表打包成功了。

把打包好的prs放到tomcat的webapp里,然后启动tomcat。

这里要注意,tomcat的访问端口要设置成和配置文件里的一样,不然用配置文件里的port是访问不到的。

打包的名称要和server.context-path=/prs的名称一致,不然也是访问不到的,这个上面已经说过了。

浏览器里输入http://127.0.0.1:8013/prs

springboot+thymeleaf打war包在外部tomcat运行的更多相关文章

  1. SpringBoot之打成war包部署到Tomcat

    正常情况下SpringBoot项目是以jar包的形式,正常情况下SpringBoot项目是以jar包的形式,并且SpringBoot是内嵌Tomcat服务器,所以每次重新启动都是用的新的Tomcat服 ...

  2. springBoot项目打war包部署到tomcat上

    1 首先得在本地跑通. 2 处理启动类Application @SpringBootApplication public class Application extends SpringBootSer ...

  3. IDEA下spring boot项目打包war包部署外部tomcat问题

    第一步,修改配置pom.xml文件 <packaging>war</packaging> <dependency> <groupId>org.sprin ...

  4. SpringBoot webmvc项目导出war包并在外部tomcat运行产生的诸多问题以及解决方案

    背景: 有需求要将原来的Spring(3.2.6) + Springmvc + Hibernate项目重构为Springboot(1.5.2)项目 描述: 记录重构过程,以及期间遇到的种种问题和对应的 ...

  5. Springboot项目打成jar包运行 和 打成war包 外部tomcat运行

    Jar打包方式运行 类型为jar时 <packaging>jar</packaging> 1.使用命令mvn clean  package 打包 2.使用java –jar 包 ...

  6. 基于springboot多模块项目使用maven命令打成war包放到服务器上运行的问题

    首先,大家看到这个问题,可能并不陌生,而且脑子里第一映像就是使用mava中的clear package 或者 clear install进行打包,然后在项目中的target文件夹下面找到xxx.war ...

  7. SpringBoot打war包并部署到外部tomcat运行(jar工程改造为正war工程)

    如果你的SpringBoot工程是一个jar工程,而想把它改造成war工程,并打成war包放到外部的tomcat下运行,该怎么修改配置呢?这里以Maven工程为例进行介绍. (1)将pom.xml中的 ...

  8. SpringBoot 项目打war包 tomcat部署

    今天看了一下springboot的项目,个人习惯是接触新的语言或框架,首先要做的就是程序员届最常用的“Hello World”,然后进行项目部署,然今天部署却发现一直都是404,查看tomcat的we ...

  9. Springboot项目打成war包,部署到tomcat上,正常启动访问报错404

    前言: 项目介绍,此项目是一个Maven多模块项目,模块项目:all(父模块):util (公用的工具类):dao(实体类.业务类.mapper.mapper.xml):business(业务serv ...

随机推荐

  1. hdu6158(圆的反演)

    hdu6158 题意 初始有两个圆,按照标号去放圆,问放完 \(n\) 个圆后的总面积. 分析 圆的反演的应用. 参考blog 设反演圆心为 \(O\) 和反演半径 \(R\) 圆的反演的定义: 已知 ...

  2. 1357:车厢调度(train)

    [题目描述] 有一个火车站,铁路如图所示,每辆火车从A驶入,再从B方向驶出,同时它的车厢可以重新组合.假设从A方向驶来的火车有n节(n≤1000),分别按照顺序编号为1,2,3,…,n.假定在进入车站 ...

  3. Visual Studio 2017 编译Clang

    到http://releases.llvm.org/download.html下载LLVM和clang源码 比如: http://releases.llvm.org/6.0.0/llvm-6.0.0. ...

  4. Mybatis全部标签

    一.定义SQL语句 (1)select 标签的使用 属性介绍: id :唯一的标识符. parameterType:传给此语句的参数的全路径名或别名 例:com.test.poso.User或user ...

  5. Java高级架构师(一)第21节:通过X-gen生成商品模块

    package com.sishuok.architecture1.goodsmgr.vo; import com.sishuok.architecture1.common.vo.BaseModel; ...

  6. &#x开头的是什么编码?

    在 Node 层利用 cheerio 解析网页时,输出的中文内容都是以 &#x 开头的一堆像乱码一样的东西,尝试过各种编码都无效,而且神奇的是,将这一堆“乱码”保存成网页后,通过浏览器打开又可 ...

  7. JNI之数据类型

    1. JNIEnv 作用 JNIEnv 概念 : 是一个线程相关的结构体, 该结构体代表了 Java 在本线程的运行环境 ; JNIEnv 与 JavaVM : 注意区分这两个概念; -- JavaV ...

  8. IIS8集成模式下打开静态资源被aspx处理程序处理,StaticFileModule失效问题分析

    问题描述: 打开js,css,jpg之类的静态资源文件触发了asp.net mvc的权限认证,并不是直接返回静态内容 问题分析: StaticFileModule 失效 ,可能是文件权限问题 问题解决 ...

  9. pdf.js 添加自定义loading动画

    最近做了个手机端pdf预览的功能,用到pdf.js这个库,效果还不错.但是在网络差.文件大时,页面一直空白,体验不是很好. 于是加了个loading动画. <div id="loadi ...

  10. mysql left join,right join,inner join的区别

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录 inner join(等值连接) ...