Spring Boot and PrettyFaces: PrettyFaces Not Loading

2.3k views Asked by At

Summary: When I turn on my Spring Boot application. (Running on the embedded Tomcat 8 server) I never receive the:

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.

Log notifications. For some reason PrettyFaces isn't starting up, and I don't know why.

Technologies: Spring Boot 1.2.0.RELEASE, Java 8, Maven for dependency management. Embedded Tomcat 8.0.15 Server.

Focusing on Java Configuration as much as possible. Previously I tried to use Rewrite, but it gave me an equal amount of gruff. Feel like I'm missing something obvious.

Here's a link to my current code base. (It's pretty small, just working on the foundation for a new project, nothing major implemented yet.)

https://github.com/MeisterGit/FoundationServer

Maven Dependency:

<dependency>
    <groupId>com.ocpsoft</groupId>
    <artifactId>prettyfaces-jsf2</artifactId>
    <version>3.3.3</version>
</dependency>`

Other Maven Dependency Tried:

<!-- 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>

Both version yield the same result. No startup messages.

I'm trying to keep XML to an absolute minimum. I have faces-config set up with:

<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>`

and my controller is topped by:

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

Here's my 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>

Any help on what I'm doing wrong? The server turns on, I can hit http://localhost:8080/content/index.xhtml just fine, and the JSF template loads. The Spring Bean backs it up. . . But no URL mapping is functioning. If I hit http://localhost:8080/ I just get an error.

1

There are 1 answers

1
Andy Wilkinson On BEST ANSWER

When you're using Spring Boot with an embedded container web.xml and web-fragment.xml are ignored. You need to register the PrettyFaces filter in your application's Java configuration:

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

Spring Boot could be improved to auto-configure this filter for you if PrettyFaces is on the classpath. If you'd like to see such an enhancement, please open an issue.