把传统的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中的更多相关文章

  1. 传值:web.xml传递参数 即在Servlet中获取web.xml里的值

    传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param <servlet> ... <init-param> <param-nam ...

  2. servlet 3.0无需配置web.xml,使用注入方式配置servlet实现登陆功能(服务器需要支持servlet3.0)

    首先申明上面的报错红叉,我也不知道怎么回事.总之能运行. 新建项目时选择java EE6.0,低版本没有servlet3.0. 先看一个基本示例. Test.java是用来测试无需配置文件,无需静态页 ...

  3. javascript中some,every,map,filter是只用和ansyc中的each,eachLimit,map,mapLImit,filter的使用

    var t = [1,2,3,4,5]; //some找到数组中第一个符合要求的值后就不在继续执行//用来判断数组中是否存符合要求的值,返回结果true|false//function返回类型为boo ...

  4. 服务器启动时Webapp的web.xml中配置的加载顺序

    一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...

  5. 服务器启动时Webapp的web.xml中配置的加载顺序(转载)

    一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...

  6. SpringMVC(十六):如何使用编程方式替代/WEB-INF/web.xml中的配置信息

    在构建springmvc+mybatis项目时,更常用的方式是采用web.xml来配置,而且一般情况下会在web.xml中使用ContextLoaderListener加载applicationCon ...

  7. web.xml中的ContextLoaderListener和DispatcherServlet区别

    ContextLoaderListener和DispatcherServlet都会在Web容器启动的时候加载一下bean配置. 区别在于: DispatcherServlet一般会加载MVC相关的be ...

  8. 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 ...

  9. Servlet中web.xml 以及 <url-pattern>总结

    web.xml中添加Servlet配置信息 使用Eclipse创建Servlet,会自动的在WEB-INF下的web.xml中声明,但是有的时候需要我们手动的写入配置信息,以下就是Servlet在we ...

随机推荐

  1. bootstrap table dataView展开行详情,p元素自动换行

    // bootstrap table 行详情展开,p元素自动换行1 .tableClass .detail-view p{ white-space: normal; }

  2. select 两层 第二个select需要加别名

    select t.id from (select xxx) t

  3. MySQL8.0安装

    背景 MySQl 8.0 出来已经有段时间了,据说性能有很大提高,在网上看过很多安装教程,大同小异, 在这里亲身实战实战下MySQL8.0在Windows10系统下的安装,以下为详细的安装步骤. 1. ...

  4. python json.dumps()函数输出json格式,使用ensure_ascii参数对中文输入的支持

    在python使用过程中,输入中文,不能正常的输出,可以使用ensure_ascii参数来解决不能输入中文的问题 代码块: import json friends={"name": ...

  5. vuex状态管理

    msvue组件间通信时,若需要改变多组件间共用状态的值.通过简单的组件间传值就会遇到问题.如:子组件只能接收但改变不了父组件的值.由此,vuex的出现就是用作各组件间的状态管理. 简单实例:vuex的 ...

  6. 3wwang的2019计划

    1.探究osg类生物----系列(35天) 已完结 [置顶]探索未知种族之osg类生物[目录]​www.3wwang.cn 2.osg中的设计模式---系列(15天) 正在创作... osg中抽象工厂 ...

  7. What is REST API

    What is REST REST is acronym for REpresentational State Transfer. It is architectural style for dist ...

  8. SQL SERVER 如何把1列多行数据 合并成一列显示

    示例 修改前:1列多行数据 修改后:合并成一列 示例语句 1 2 3 4 5 6 7 8 9 10 11 select 类别,     名称 = (         stuff(            ...

  9. WCF系列_WCF常用绑定选择

    一.五种常用绑定常用绑定的传输协议以及编码格式 名称 传输协议 编码格式 互操作性 BasicHttpBinding HTTP/HTTPS Text,MTOM Yes NetTcpBinding TC ...

  10. Vmware 无法启动虚拟机 -VMware Workstation and Device/Credential Guard are not compatible.

    因为在学习Linux,起初尝试用Hyper-V安装Linux进行学习,之后为了方便和老师的设置一样,所以改装了VMware,所有初始设置先好后发现,虚机机无法启用. VMware也提示不支持CPU虚拟 ...