要使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());}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)