springboot/jsf白标签错误,仅作为intellij中的模块

csga3l58  于 2021-07-15  发布在  Java
关注(0)|答案(0)|浏览(217)

我尝试用springboot和jsf创建一个项目。作为一个独立的项目,它的工作和下”localhost:8080/hello.xhtml“hello.xhtml确实会弹出,但作为已存在项目中的一个模块,它找不到资源-->白标签错误页。。。出现意外错误(类型=未找到,状态=404)。
有人有主意吗?
模块结构

spring-jsf
 |    
 +-- src
 |  |  
 |  +-- main
 |     |
 |     +-- java 
 |     |  |
 |     |  +-- com.example.springjsf
 |     |     |
 |     |     +-- SpringJsfApplication
 |     |
 |     +-- resources
 |     |  |
 |     |  +-- application.yml
 |     |
 |     +-- webapp
 |        |
 |        +-- WEB-INF
 |        |  |
 |        |  +-- faces-config.xml
 |        |
 |        +-- hello.xhtml
 |
 +-- pom.xml

SpringJSF应用程序.java

package com.example.springjsf;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import javax.faces.webapp.FacesServlet;
import javax.servlet.ServletContext;
import java.util.Arrays;

@SpringBootApplication
public class SpringJsfApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringJsfApplication.class, args);
    }

    @Bean
    ServletRegistrationBean jsfServletRegistration (ServletContext servletContext) {
        //spring boot only works if this is set
        servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());

        //FacesServlet registration
        ServletRegistrationBean srb = new ServletRegistrationBean();
        srb.setServlet(new FacesServlet());
        srb.setUrlMappings(Arrays.asList("*.xhtml"));
        srb.setLoadOnStartup(1);
        return srb;
    }

}

pom.xml文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-jsf</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-jsf</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

faces-config.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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/web-facesconfig_2_2.xsd"
              version="2.2">

    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>

</faces-config>

你好.xhtml

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

<h:body>
    <h:form>
        <h:outputText id="hello-output" value="Hello" />
        <br/>
    </h:form>
</h:body>
</html>

当我尝试调用hello.xhtml时的控制台

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.4)

2021-03-26 14:36:20.511  INFO 23616 --- [           main] c.e.springjsf.SpringJsfApplication       : Starting SpringJsfApplication using Java 11.0.3 on LHIND-N310084 with PID 23616 (C:\Users\U730213\Development\Windpulse\lee\spring-jsf\target\classes started by U730213 in C:\Users\U730213\Development\Windpulse\lee)
2021-03-26 14:36:20.515  INFO 23616 --- [           main] c.e.springjsf.SpringJsfApplication       : No active profile set, falling back to default profiles: default
2021-03-26 14:36:21.294  INFO 23616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-03-26 14:36:21.303  INFO 23616 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-03-26 14:36:21.303  INFO 23616 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-03-26 14:36:21.537  INFO 23616 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2021-03-26 14:36:21.555  INFO 23616 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-03-26 14:36:21.555  INFO 23616 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 982 ms
2021-03-26 14:36:21.612  INFO 23616 --- [           main] j.e.resource.webcontainer.jsf.config     : Mojarra 2.2.17 ( 20180411-2323 53e5a1509f6706550c6789ced710eb6ebf05fffd) für Kontext '' wird initialisiert.
2021-03-26 14:36:21.680  INFO 23616 --- [           main] j.e.r.webcontainer.jsf.application       : JSF1048: PostConstruct/PreDestroy-Annotationen vorhanden.  Verwaltete Bean-Methoden, die mit diesen Annotationen markiert sind, lassen die entsprechenden Annotationen verarbeiten.
2021-03-26 14:36:22.007  INFO 23616 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-26 14:36:22.014 DEBUG 23616 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2021-03-26 14:36:22.048 DEBUG 23616 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2021-03-26 14:36:22.066 DEBUG 23616 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2021-03-26 14:36:22.070 DEBUG 23616 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2021-03-26 14:36:22.121  INFO 23616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-03-26 14:36:22.129  INFO 23616 --- [           main] c.e.springjsf.SpringJsfApplication       : Started SpringJsfApplication in 1.951 seconds (JVM running for 2.744)
2021-03-26 14:36:33.360  INFO 23616 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-03-26 14:36:33.361  INFO 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-03-26 14:36:33.361 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2021-03-26 14:36:33.361 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Detected AcceptHeaderLocaleResolver
2021-03-26 14:36:33.361 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Detected FixedThemeResolver
2021-03-26 14:36:33.361 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@193d3b10
2021-03-26 14:36:33.362 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Detected org.springframework.web.servlet.support.SessionFlashMapManager@53cee7b7
2021-03-26 14:36:33.362 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2021-03-26 14:36:33.362  INFO 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2021-03-26 14:36:33.364 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2021-03-26 14:36:33.369 DEBUG 23616 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
2021-03-26 14:36:33.393 DEBUG 23616 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
2021-03-26 14:36:33.396 DEBUG 23616 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404

应用程序.yml

logging:
  level:
    org.springframework.web: debug

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题