Java JSF标签don';t在XHTML页面中呈现-Spring Boot+;JSF2.2

Java JSF标签don';t在XHTML页面中呈现-Spring Boot+;JSF2.2,java,spring,spring-boot,jsf,Java,Spring,Spring Boot,Jsf,我正在尝试使用SpringBoot和JSF2.2实现一个webapp 我已经成功地正确设置了Spring Boot,并且可以用控制器显示正常的HTML。但是XHTML页面没有正确呈现 我相信这与我的配置有关,但我不知道它是什么 我在macOS High Sierra上使用IntelliJ IDEA Ultimate 2018.1 这是我的pom.xl <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://ma

我正在尝试使用SpringBoot和JSF2.2实现一个webapp

我已经成功地正确设置了Spring Boot,并且可以用控制器显示正常的HTML。但是XHTML页面没有正确呈现

我相信这与我的配置有关,但我不知道它是什么

我在macOS High Sierra上使用IntelliJ IDEA Ultimate 2018.1

这是我的pom.xl

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

    <groupId>group</groupId>
    <artifactId>spring-jsf-webapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

    <properties>
        <start-class>com.latwoa.Application</start-class>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.17</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.17</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Package as an executable jar/war -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
以及XHTML页面:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:jsf="http://xmlns.jcp.org/jsf">
<f:view>

    <h:head></h:head>

    <!--Main Body -->
    <h:body>

        <h1>Welcome to JSF spring boot tutorial</h1>

        <h:outputText value="foo bar" />

        <h3>#{jsfBean.welcomeMessage}</h3>

    </h:body>

</f:view>
</html>

欢迎来到JSF spring引导教程
#{jsfBean.welcomeMessage}
正如我上面提到的,
显示良好。但是
{jsfBean.welcomeMessage}
不会被呈现

在这里郊游

您似乎错过了使用Spring Boot配置JSF的步骤

@EnableAutoConfiguration
@ComponentScan({"com.auth0.samples.bootfaces"})
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        return new ServletRegistrationBean(servlet, "*.jsf");
    }
}
我还将添加以下侦听器以将spring上下文与托管bean集成:

   <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

org.springframework.web.context.ContextLoaderListener
org.springframework.web.context.request.RequestContextListener

您是否查看了客户端上的html源代码?然后寻找重复的问题。我认为(99%肯定)这是因为您包含了JSFAPI,而不是impl@Kukeltje我有。源代码显示了literal
标记。我的依赖项中确实有jsf impl,但我没有注意到
true
标记。这可能是导致错误的原因吗?对不起,我把它们弄混了。不会怀疑可选项相关,但您可以尝试。SpringBoot已经包含JSFAPI了吗?SpringBoot既不包含JSFAPI也不包含impl。您需要具有
compile
范围的两个依赖项,而不是可选的。除此之外,
@ManagedBean
不能与Spring Boot一起工作(至少我自己不能让它工作)。这里是我用Spring Boot 1配置它所做的:我以前看过该教程,将
@Bean
添加到我的
应用程序
会给我这个错误,从而使事情变得更糟:
白标错误页这个应用程序没有显式的/error映射,因此您将此视为一种回退。2018年6月22日星期五20:53:42英国夏令时出现意外错误(类型=内部服务器错误,状态=500)。找不到工厂javax.faces.context.FacesContextFactory的备份我找不到“找不到工厂javax.faces.context.FacesContextFactory的备份”的修复程序
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:h="http://xmlns.jcp.org/jsf/html"
   xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:jsf="http://xmlns.jcp.org/jsf">
<f:view>

    <h:head></h:head>

    <!--Main Body -->
    <h:body>

        <h1>Welcome to JSF spring boot tutorial</h1>

        <h:outputText value="foo bar" />

        <h3>#{jsfBean.welcomeMessage}</h3>

    </h:body>

</f:view>
</html>
@EnableAutoConfiguration
@ComponentScan({"com.auth0.samples.bootfaces"})
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        return new ServletRegistrationBean(servlet, "*.jsf");
    }
}
   <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>