Spring Boot 和 PrettyFaces:PrettyFaces 未加载

Set*_*son 4 prettyfaces jsf-2.2 spring-boot

摘要:当我打开 Spring Boot 应用程序时。(在嵌入式 Tomcat 8 服务器上运行)我从未收到过:

INFO  [org.ocpsoft.rewrite.servlet.RewriteFilter] RewriteFilter starting up...
...
INFO  [org.ocpsoft.rewrite.servlet.RewriteFilter] Loaded [] org.ocpsoft.rewrite.config.ConfigurationProvider [org.ocpsoft.rewrite.prettyfaces.PrettyFacesRewriteConfigurationProvider<1>]
INFO  [org.ocpsoft.rewrite.servlet.RewriteFilter] RewriteFilter initialized.
Run Code Online (Sandbox Code Playgroud)

记录通知。出于某种原因,PrettyFaces 没有启动,我不知道为什么。

技术:Spring Boot 1.2.0.RELEASE、Java 8、用于依赖管理的Maven。嵌入式 Tomcat 8.0.15 服务器。

尽可能专注于 Java 配置。以前我尝试使用 Rewrite,但它给了我同等数量的粗暴。感觉我错过了一些明显的东西。

这是我当前代码库的链接。(它很小,只是在为一个新项目打基础,还没有什么大的实施。)

https://github.com/MeisterGit/FoundationServer

Maven 依赖:

<dependency>
    <groupId>com.ocpsoft</groupId>
    <artifactId>prettyfaces-jsf2</artifactId>
    <version>3.3.3</version>
</dependency>`
Run Code Online (Sandbox Code Playgroud)

其他 Maven 依赖尝试:

<!-- PrettyFaces -->
<dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-servlet</artifactId>
    <version>2.0.12.Final</version>
</dependency>
<dependency>
    <groupId>org.ocpsoft.rewrite</groupId>
    <artifactId>rewrite-config-prettyfaces</artifactId>
    <version>2.0.12.Final</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

两个版本产生相同的结果。没有启动消息。

我试图将 XML 保持在最低限度。我已经设置了faces-config:

<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
        http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
        version="2.2">

    <!-- Allow Spring Beans to be accessible to JSF. -->
    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>
</faces-config>`
Run Code Online (Sandbox Code Playgroud)

我的控制器是:

@Controller
@URLMapping(id = UserController.INDEX,
        pattern = "/",
        viewId = "/content/index.xhtml") // Home page.`
Run Code Online (Sandbox Code Playgroud)

这是我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="foundation-server"
    version="3.1">

<!-- PrettyFaces: Specify which package to scan for @UrlMapping annotations --> 
<context-param>
   <param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>
   <param-value>foundation</param-value>
</context-param>

<!--  No Pretty Filter required, servlet 3.0+ automatically registers the filter. -->
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

对我做错了什么有帮助吗?服务器打开,我可以http://localhost:8080/content/index.xhtml正常运行,然后加载 JSF 模板。Spring Bean 支持它。. . 但是没有 URL 映射在起作用。如果我点击,http://localhost:8080/我只会得到一个错误。

And*_*son 5

当您将 Spring Boot 与嵌入式容器一起使用web.xml并被web-fragment.xml忽略时。您需要PrettyFaces在应用程序的 Java 配置中注册过滤器:

@Bean
public FilterRegistrationBean prettyFilter() {
    FilterRegistrationBean prettyFilter = new FilterRegistrationBean(new PrettyFilter());
    prettyFilter.setDispatcherTypes(DispatcherType.FORWARD, DispatcherType.REQUEST,
            DispatcherType.ASYNC, DispatcherType.ERROR);
    prettyFilter.addUrlPatterns("/*");
    return prettyFilter;
}
Run Code Online (Sandbox Code Playgroud)

如果 PrettyFaces 在类路径上,Spring Boot 可以改进为自动配置这个过滤器。如果你想看到这样的增强,请打开一个问题