如何把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 ...
随机推荐
- Vue element 分页
Vue单页面,有一个带分页的表格,表格内数据关联页码,套路如下: 代码如下: <div class="c-table-list auth-list m-bottom-20"& ...
- textarea下高度自适应
1,背景:textarea的高度不会随内容的增加而自适应,会出现滚动条 解决方案: 1)使用div模拟textarea 使用h5的属性 <div contenteditable=&quo ...
- jquery 上下文菜单实现
话不多说,直接贴上官方demo演示: https://swisnl.github.io/jQuery-contextMenu//demo
- 解决ubuntu 图标消失问题(ubuntu 16)
如题,我的ubuntu 16 在安装了新内核并重启之后,所有的图标都消失了. (可能和新内核没有多大关系,我切回旧内核也那样) 是什么bug我不清楚,但是图标原有的位置还是可以点击的,仔细看图标还在, ...
- ZOJ 2507 Let's play a game
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1507 MisereNim博弈.代码如下: //=========== ...
- union: redis config
# how to save to disk # warning: how to disable, just comment this config save $second $changes
- PCL-安装
1.安装定期更新维护的PCL开发包. 通过PPA支持的Ubuntu系统,安装命令为: sudo add-apt-repository ppa:v-launched-jochen-sprickerhof ...
- java33
1.面向接口编程:将实现类对象(键盘鼠标)赋值给接口类型的变量(USB) interface修饰的类名称 好处:调用时可以是一个方法体即可(实现通用编程) 2.内部类:在类中定义了一个类 ------ ...
- 《Linux就该这么学》第十三天课程
使用Apache服务部署静态网站 原创地址:https://www.linuxprobe.com/chapter-10.html 今天学了Apache,这只是RHCE课程的开始,估计后面越来越难 今天 ...
- UEditor可以如何直接复制word的图文内容到编辑器中?
下载并打开工程: 文档的上传 运行: 复制随便一篇文档,粘贴进去. 通过粘贴后,文档以及图片被粘贴进来了,看看html代码: 图片全部使用img标签统一.传输进度条的效果也不错. 文档图片被放置在 ...