You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Richfaces3.x迁移SpringBoot1.5.22启动及页面渲染报错求助

SpringBoot 1.5.x迁移Richfaces3.x问题解决方案

1. ContextLoaderListener冲突解决

SpringBoot已自动注册ContextLoaderListener,手动添加会引发冲突:

  • 删除自定义ServletContextInitializer里手动注册的ContextLoaderListener
  • 保留SpringBoot自动配置,无需重复初始化Spring上下文

2. Log4jConfigListener异常处理

SpringBoot 1.5.x默认用Logback,若项目依赖Log4j,需调整依赖配置:

  • 排除SpringBoot自带的Logback依赖,在pom.xml中添加:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
  • 移除Log4jConfigListener的手动注册,SpringBoot会自动加载classpath下的log4j.properties或log4j.xml

3. javax.faces.context.FacesContextFactory找不到问题

Richfaces3.x依赖JSF 1.2,需确保依赖正确引入:

  • 添加JSF 1.2(如Mojarra 1.2)依赖:
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>1.2_15</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>1.2_15</version>
</dependency>
  • 避免SpringBoot自动引入高版本JSF,如有冲突需排除相关自动配置

4. 添加ConfigureListener后FacesServlet报错

需正确注册FacesServlet并配置映射,同时确保Richfaces配置加载:

  • 在自定义ServletContextInitializer中注册FacesServlet:
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    // 注册FacesServlet
    ServletRegistration.Dynamic facesServlet = servletContext.addServlet("FacesServlet", javax.faces.webapp.FacesServlet.class);
    facesServlet.setLoadOnStartup(1);
    facesServlet.addMapping("*.jsf", "*.faces", "/faces/*");
    
    // 注册Richfaces的ConfigureListener
    servletContext.addListener(org.ajax4jsf.webapp.ConfigureListener.class);
    
    // 设置JSF项目阶段,适配开发环境
    servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
}
  • 检查FacesServlet映射路径是否与原web.xml一致,避免路径不匹配导致404

5. 移除过滤器后资源框架未初始化

Richfaces3.x核心过滤器是资源加载必需的,不能直接移除:

  • 在ServletContextInitializer中注册Richfaces核心过滤器:
FilterRegistration.Dynamic richfacesFilter = servletContext.addFilter("richfaces", org.ajax4jsf.Filter.class);
richfacesFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
  • 确保过滤器映射路径覆盖所有JSF请求,保证CSS、JS等资源正常加载

额外注意事项

  • 版本兼容性:SpringBoot 1.5.22对应Spring 4.3.25.RELEASE,需搭配兼容的Richfaces3.x版本(如3.3.4.Final)
  • 原web.xml中的初始化参数,需通过servletContext.setInitParameter()迁移到ServletContextInitializer中
  • 清理项目中过时的配置文件,避免与SpringBoot自动配置冲突

内容的提问来源于stack exchange,提问作者David S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 13:05:06