如何把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 ...
随机推荐
- mkfs.ext4快速格式化大容量硬盘
安装ext4: yum -y install e4fsprogs 使用如下命令可以快速格式化大容量硬盘: mkfs.ext4 -T largefile /dev/xxx
- kubernetes 常见问题整理
使用kubectl 命令是报错 报错: [root@k8s-master ~]# kubectl get pod The connection to the server localhost: was ...
- python日志
日志 -- 用来记录用户行为或者代码的执行过程 logging.debug('debug message') # 低级别的 # 排错信息 logging.info('info message') # ...
- 第一次面试经历(hr面)
经过介绍,我有幸去到一家国际背景的广告公司面试前端开发实习生.收到的邮件是复试通知,看来我已经跳过了第一轮面试. 来到hr请我进了一个小间坐下里填求职书,里面有各种个人信息,有兴趣爱好,有工作经历,以 ...
- C++重载Level蓝图
一.从ALevelScriptActor派生自己的类,添加功能并编译. 二.在编辑器中打开level blueprint,然后class default选项卡中,在细节面板中Parent class选 ...
- mysql读写分离——中间件ProxySQL的简介与配置
mysql实现读写分离的方式 mysql 实现读写分离的方式有以下几种: 程序修改mysql操作,直接和数据库通信,简单快捷的读写分离和随机的方式实现的负载均衡,权限独立分配,需要开发人员协助. am ...
- 适用于Mac 的自动补丁管理软件
适用于Mac 的自动补丁管理软件 ManageEngine Desktop Central 的功能越来越神奇.系统管理员现在可以使用 Desktop Central 管理异构网络.即使是最复杂的任务, ...
- Postfix邮件服务器
http://www.postfix.org/INSTALL.html https://www.cnblogs.com/alex-note/p/6840160.html http://linux.vb ...
- 第五周助教工作总结——NWNU李泓毅
第五周助教总结 注:因第四次实验安排两个标准时间完成,因此本周未提交完整作业. 本周心得: 第四次实验进行过半,八组同学都在实验课上进行了一次中期总结,并形成书面总结在微信群中讨论. 根据各组同学的中 ...
- netcore程序部署及守护
一.程序发布 1.在本机编译无误的情况下,选择发布成文件系统.注意如果使用了swagger 需要将生成的xml文档说明复制到发版包里面.否则会报错.(可以在项目的csproj 中加入 <Prop ...