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

使用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());}}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/4896104.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存