SpringBoot使用外置的Servlet容器
2024-10-19 00:31:15
SpringBoot默认使用嵌入式的Servlet容器,应用打包成可执行的jar包
优点:简单、便携
缺点:默认不支持jsp,优化定制比较复杂(使用定制器serverProperties、自定义EmbeddedServletContainerCustomizer,自己编写嵌入式Servlet容器的创建工厂EmbeddedServletContainerFactory)
*SpringBoot使用外置的Servlet容器条件
1.安装外置Servlet容器【tomcat】
2.使用war方式进行打包
(1)、使用Spring初始化向导创建war SpringBoot项目
(2)在Project Structure窗口创建目录结构
(3)在运行窗口配置外置Tomcat
(4)修改配置文件
(5)将嵌入式的Tomcat指定为provided
(6)编写一个SpringBootServletInitializer的子类,并调用configure方法
package cn.coreqi; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; /**
* 必须编写一个SpringBootServletInitializer的子类,并调用configure方法
*/
public class ServletInitializer extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//传入SpringBoot应用的主程序
return application.sources(SpringbootwarApplication.class);
} }
(7)编写控制器、jsp页面后点击tomcat运行即可
最新文章
- SpringMVC学习系列(9) 之 实现注解式权限验证
- 粒子群优化算法(Particle Swarm Optimization)
- nodejs快速入门
- html-----012---颜色的改变
- Eclipse中使用git把项目导入到osc@git中
- AJAX 控件集之TextBoxWatermark(水印文本框)控件
- [Day03] 循环语句、list相关练习题
- git学习之创建版本库
- css盒子居中定位问题
- upstream timed out (110: Connection timed out) while reading response header from upstream, client:
- weakhashmap简单理解
- h3c acl配置一列
- MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) - 转载
- C# Azure 远程调试
- iOS视频流开发(2)—视频播放
- 学JS的心路历程 - PixiJS -基础(一)
- 【转】H.264 SVC
- 10BASE
- Modbus Com SerialPort
- jQuery--修改表单数据并提交