如何把web.xml中的context-param、Servlet、Listener和Filter定义添加到SpringBoot中
把传统的web项目迁移到SpringBoot中,少不了web.xml中的context-param、Servlet、Filter和Listener等定义的迁移。 对于Servlet、Filter和Listener相关定义转换相对来说比较明确:
Servlet定义的迁移
一般servlet的迁移
@WebServlet("/jsonIndexSearchServlet")
public class JsonIndexSearchServlet extends HttpServlet {
...
}
FacesServlet的迁移
@Bean
public ServletRegistrationBean servletRegistrationBean() {
FacesServlet servlet = new FacesServlet();
//, "*.jsf"
ServletRegistrationBean bean = new ServletRegistrationBean(servlet);
bean.setOrder(40);
bean.setName("FacesServlet");
List<String> urlPattern = new ArrayList<>();
urlPattern.add("*.jsf");
bean.setUrlMappings(urlPattern);
return bean;
}
Listener定义的迁移
@Bean
public ServletListenerRegistrationBean<ServletContextListener> setStartupServletContextListener(){
ServletListenerRegistrationBean<ServletContextListener> result = new ServletListenerRegistrationBean<>();
result.setListener(new StartupServletContextListener());
result.setOrder(20);
return result;
}
Filter定义的迁移
@Bean
public FilterRegistrationBean rewriteFilter() {
FilterRegistrationBean rwFilter = new FilterRegistrationBean(new RewriteFilter());
rwFilter.setDispatcherTypes(EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST,
DispatcherType.ASYNC, DispatcherType.ERROR));
rwFilter.addUrlPatterns("/*");
rwFilter.setOrder(30);
return rwFilter;
}
context-param定义的迁移
@Bean
public InitParameterConfiguringServletContextInitializer initParamsInitializer() {
Map<String, String> contextParams = new HashMap<>();
contextParams.put("org.apache.myfaces.AUTO_SCROLL", "true");
return new InitParameterConfiguringServletContextInitializer(contextParams);
}
如何把web.xml中的context-param、Servlet、Listener和Filter定义添加到SpringBoot中的更多相关文章
- 传值:web.xml传递参数 即在Servlet中获取web.xml里的值
传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param <servlet> ... <init-param> <param-nam ...
- servlet 3.0无需配置web.xml,使用注入方式配置servlet实现登陆功能(服务器需要支持servlet3.0)
首先申明上面的报错红叉,我也不知道怎么回事.总之能运行. 新建项目时选择java EE6.0,低版本没有servlet3.0. 先看一个基本示例. Test.java是用来测试无需配置文件,无需静态页 ...
- javascript中some,every,map,filter是只用和ansyc中的each,eachLimit,map,mapLImit,filter的使用
var t = [1,2,3,4,5]; //some找到数组中第一个符合要求的值后就不在继续执行//用来判断数组中是否存符合要求的值,返回结果true|false//function返回类型为boo ...
- 服务器启动时Webapp的web.xml中配置的加载顺序
一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...
- 服务器启动时Webapp的web.xml中配置的加载顺序(转载)
一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...
- SpringMVC(十六):如何使用编程方式替代/WEB-INF/web.xml中的配置信息
在构建springmvc+mybatis项目时,更常用的方式是采用web.xml来配置,而且一般情况下会在web.xml中使用ContextLoaderListener加载applicationCon ...
- web.xml中的ContextLoaderListener和DispatcherServlet区别
ContextLoaderListener和DispatcherServlet都会在Web容器启动的时候加载一下bean配置. 区别在于: DispatcherServlet一般会加载MVC相关的be ...
- J2EE中使用jstl报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar错
一.发现问题 运行引用了jstl的jsp页面 报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or th ...
- Servlet中web.xml 以及 <url-pattern>总结
web.xml中添加Servlet配置信息 使用Eclipse创建Servlet,会自动的在WEB-INF下的web.xml中声明,但是有的时候需要我们手动的写入配置信息,以下就是Servlet在we ...
随机推荐
- Kafka的安装及与Spring Boot的集成
安装JDK 下载jdk-8u202-ea-bin-b03-linux-x64-07_nov_2018.tar.gz 解压 配置 $ vi /etc/profile,在最后加入下面两行 export J ...
- 安装CentOS 7 的yum 到 Radhat 7上,使其可以获取资源
镜像资源: 1. http://mirrors.163.com/ 2. https://opsx.alibaba.com/mirror 从上列镜像资源下载如下rpm软件包 -rw-r--r--. 1 ...
- Maven 生成可执行的jar包
maven 默认打包生成的 jar 包是不能够直接运行的,因为带有 main 方法的类信息不会添加到 manifest 中,即打开 jar 文件中的 META-INF/MANIFEST.MF 文件,将 ...
- 分享一个mac for redis-desktop-manager破解版安装包
链接: https://pan.baidu.com/s/1BDndGmBlWoSr4hVLpF3FVw 提取码: wwir
- 距离不是一个连续的物理量(Distance is not a continuous physical quantity)
量子距:不同于现有物理学的长度计量.量子距,空间中的两个粒子之间的距离并不是连续的,而是某个单位距(量子单位距)的整数倍,而这个距离被称为量子距. Quantum distance: Length m ...
- 数组,arrayList和List
数组,arrayList和List (1)数组在C#中是最早出现的.它在内存中是连续的存储的,所以索引速度很快,而且赋值与修改元素也很简单.可以利用偏移地址访问元素,时间复杂度为O(1);可以用折半查 ...
- Failed to mount component: template or render function not defined.
Failed to mount component: template or render function not defined. vue-loader13.0有一个变更就是默认启用了esModu ...
- GitHub上高质量项目
scribejava/scribejava:一个简单的 Java 实现的 OAuth/OAuth2 库winterbe/java8-tutorial:绝对值得一看的Java8指南.教程javaee-s ...
- html4
一.span标签:能让某几个文字或者某个词语凸显出来 <p> 今天是11月份的<span>第一天</span>,地铁卡不打折了 </p> 二.字体风格 ...
- EasyUI 学习(1)-Tooltip(提示框)
一.创建组件 Tooltip不依赖其他组件 1.使用class加载 <a href="#" class="easyui-tooltip" title=&q ...