springBoot学习之路之使用外置的servlet容器
嵌入式的servlet 容器:
优点:简单、便携
缺点: 默认是不支持jsp的、优化定制比较复杂(1.使用定制器 2.自己编写嵌入式的的servlet的工厂);
外置的servlet容器;外面安装tomcat—应用war包
步骤:
1.创建一个war项目
2.将嵌入式的servlet指定为provide provide
告诉ide已经有环境了不需要再讲嵌入式的servlet打包进项目
3.一定要有一个 继承SpringbootServletInitalizer 的类并调用configure 方法 才能启动外置的servlet容器
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);
}
}
4.再启动服务就可以使用外置servlet容器