栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用JSF的Spring Boot;找不到工厂javax.faces.context.FacesContextFactory的备份

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用JSF的Spring Boot;找不到工厂javax.faces.context.FacesContextFactory的备份

要使JSF在不带的Spring Boot上运行,

web.xml
或者
faces-config.xml
您需要通过上的init参数强制其加载其配置文件
ServletContext
。一个简单的方法是实现
ServletContextAware

public class Application implements ServletContextAware {    // ...    @Override    public void setServletContext(ServletContext servletContext) {        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());    }}

JSF

ConfigureListener
还依赖于JSP,因此您需要在pom中添加对Jasper的依赖:

<dependency>    <groupId>org.apache.tomcat.embed</groupId>    <artifactId>tomcat-embed-jasper</artifactId></dependency>

它与您的问题没有直接关系,但是您不需要声明

FacesServlet
为bean。该
ServletRegistrationBean
是足够了。

这使得

Application.java
寻找如下:

import javax.faces.webapp.FacesServlet;import javax.servlet.ServletContext;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.context.embedded.ServletListenerRegistrationBean;import org.springframework.boot.context.embedded.ServletRegistrationBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.web.context.ServletContextAware;import com.sun.faces.config.ConfigureListener;@Configuration@EnableAutoConfiguration@ComponentScanpublic class Application implements ServletContextAware {    public static void main(String[] args) {        SpringApplication.run(Application.class);    }    @Bean    public ServletRegistrationBean facesServletRegistration() {        ServletRegistrationBean registration = new ServletRegistrationBean( new FacesServlet(), "*.xhtml");        registration.setLoadonStartup(1);        return registration;    }    @Bean    public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {        return new ServletListenerRegistrationBean<ConfigureListener>( new ConfigureListener());    }    @Override    public void setServletContext(ServletContext servletContext) {        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());}}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367867.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号