工程目录

pom文件注意点

  1. <packaging>war</packaging>
  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-tomcat</artifactId>
  4. <scope>provided</scope>
  5. </dependency>
  1. <build>
  2. <finalName>prs</finalName>
  3. <plugins>
  4. <plugin>
  5. <groupId>org.apache.maven.plugins</groupId>
  6. <artifactId>maven-compiler-plugin</artifactId>
  7. </plugin>
  8. </plugins>
  9. </build>

配置文件application.properties

  1. server.port=
  2. server.session.timeout=
  3. server.context-path=/prs
  4.  
  5. #thymelea模板配置
  6. spring.thymeleaf.prefix=classpath:/templates/
  7. spring.thymeleaf.suffix=.html
  8. spring.thymeleaf.mode=HTML5
  9. spring.thymeleaf.encoding=UTF-
  10. spring.thymeleaf.content-type=text/html
  11. spring.thymeleaf.cache=false
  12. #spring.resources.chain.strategy.content.enabled=true
  13. #spring.resources.chain.strategy.content.paths=/**
  14.  
  15. # 上传文件大小配置
  16. spring.http.multipart.maxFileSize=10MB
  17. spring.http.multipart.maxRequestSize=10MB
  18.  
  19. #spring.mvc.async.request-timeout=600000
  20. #spring.http.multipart.max-request-size=200MB
  21.  
  22. #spring.aop.auto=true
  23. #spring.aop.proxy-target-class=false
  24.  
  25. #server.tomcat.uri-encoding=UTF-8
  26. #server.tomcat.max-threads=100
  27. logging.config=classpath:logback.xml
  28.  
  29. #mybatis.configLocation=classpath:mybatis/mybatis-config.xml
  30. #mybatis.mapperLocations=classpath:mybatis/mapper/*.xml
  31.  
  32. #spring.datasource.driverClassName = com.mysql.jdbc.Driver
  33. #com.microsoft.sqlserver.jdbc.SQLServerDriver
  34. #spring.datasource.url = jdbc:mysql://127.0.0.1:3306/test
  35. #jdbc:sqlserver://104.15.202.101:1105;DatabaseName=tt
  36. #spring.datasource.username = root
  37. #spring.datasource.password = 123456
  38.  
  39. #spring.datasource.initialSize=2
  40. #spring.datasource.minIdle=0
  41. #spring.datasource.maxActive=5
  42. #spring.datasource.maxWait=60000
  43. #spring.datasource.validationQuery=select 1
  44. #spring.datasource.timeBetweenEvictionRunsMillis=60000
  45. #spring.datasource.testWhileIdle=true
  46. #spring.datasource.testOnBorrow=true
  47. #spring.datasource.testOnReturn=false
  48. #spring.datasource.poolPreparedStatements=true
  49. #spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
  1. server.context-path=/prs这里的路径名最好和上面pom里的finalName最好是一致的,因为当我们把打包好的war包放到tomcatwebapp里时,访问路径前缀就是这个finalName

启动类

  1. @ComponentScan(basePackages= {"com.wymessi"})//扫描组件
  2. @SpringBootApplication
  3. @EnableAspectJAutoProxy
  4. @EnableTransactionManagement(proxyTargetClass = true)
  5. @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class})
  6. public class SpringbootApplication extends SpringBootServletInitializer {
  7.  
  8. public static void main(String[] args) {
  9. SpringApplication.run(SpringbootApplication.class, args);
  10. }
  11.  
  12. @Override
  13. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  14. // 注意这里要指向原先用main方法执行的Application启动类
  15. return builder.sources(SpringbootApplication.class);
  16. }
  17.  
  18. // @Bean
  19. // public HttpMessageConverters fastJsonHttpMessageConverters() {
  20. // FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
  21. // FastJsonConfig fastJsonConfig = new FastJsonConfig();
  22. // // fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserCompatible);
  23. // // fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserSecure);
  24. // fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
  25. // // fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
  26. // SerializeConfig config = new SerializeConfig();
  27. // config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
  28. // fastJsonConfig.setSerializeConfig(config);
  29. // fastConverter.setFastJsonConfig(fastJsonConfig);
  30. // HttpMessageConverter<?> converter = fastConverter;
  31. // return new HttpMessageConverters(converter);
  32. // }
  33.  
  34. }

和打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. Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. java中的控制语句

    控制语句 1.1 顺序结构 (最常见的) 特点:代码从上往下依次执行 1.2 选择结构 : if 判断语句 : switch 判断语句: Switch语句使用的注意事项: 1.每一个语句结束后需要有一 ...

  3. 【枚举】【贪心】 Codeforces Round #398 (Div. 2) B. The Queue

    卡题意……妈的智障 一个人的服务时间完整包含在整个工作时间以内. 显然,如果有空档的时间,并且能再下班之前完结,那么直接输出即可,显然取最左侧的空档最优. 如果没有的话,就要考虑“挤掉”某个人,就是在 ...

  4. linux的打包与解压

    zip: 打包 :zip something.zip something (目录请加 -r 参数) 解包:unzip something 指定路径:-d 参数 创建加密 zip 包 使用 -e 参数可 ...

  5. 解决Windows服务修改配置文件后必须重启的问题

      原文地址:http://www.cnblogs.com/jeffwongishandsome/archive/2011/04/24/2026381.html   解决方法:读取配置文件前先刷新文件 ...

  6. SQL 日期格式化函数

    Sql Server 中一个非常强大的日期格式化函数: 获得当前系统时间,GETDATE(): 2008年01月08日 星期二 14:59 Select CONVERT(varchar(100), G ...

  7. Oracle RMAN 备份及不完全恢复(删除archievelog)

    RMAN备份命令 backup Database format='/home/oracle/backup/bak_full_%U_%T' tag='bak_full'; sql 'alter syst ...

  8. php漏洞挖掘书籍

    PHP是一种被广泛使用的脚本语言,尤其适合web开发.具有跨平台,容易学习,功能强大等特点,据统计全世界超过34%的网站有php的应用,包括Yahoo.sina.163.sohu等大型门户网站.而且很 ...

  9. 通过python脚本查看端口

    [root@zabbix-server alertscripts]# cat check_port1.py #!/usr/bin/env python #coding:utf-8 import os, ...

  10. 【AS3 Coder】任务九:游戏新手引导的制作原理(上)

    使用框架:AS3任务描述:了解游戏中新手的制作原理及流程 难度:3 本章源码下载:http://www.iamsevent.com/zb_users/UPLOAD/GuideManager/Test1 ...