当前位置: 首页 > 知识库问答 >
问题:

如何通过嵌入式tomcat将spring boot与JSF2.2集成

怀晋
2023-03-14
<?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>com.kp.swasthik</groupId>
    <artifactId>kp-sb-jsf</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>kp-sb-jsf</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.M5</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <primefaces.version>5.2</primefaces.version>
        <!-- <jsf.version>2.2.8</jsf.version> -->
        <jsf.version>2.2.12</jsf.version>
        <jsf.extension.version>3.2.0</jsf.extension.version>
        <jsf.themes.version>1.0.10</jsf.themes.version>
        <spring.webflow.version>2.4.2.RELEASE</spring.webflow.version>
        <omnifaces.version>2.1</omnifaces.version>
        <wield.version>2.2.15.Final</wield.version>
    </properties>

    <dependencies>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>2.2</version>
    </dependency>

       <!--
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>${omnifaces.version}</version>
        </dependency>
       -->

        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet</artifactId>
            <version>${wield.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>


        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>${primefaces.version}</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>${jsf.extension.version}</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>${jsf.themes.version}</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>resources-optimizer-maven-plugin</artifactId>
            <version>2.0.0</version>
        </dependency>


        <!-- <dependency> <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-impl</artifactId> 
            <version>${jsf.version}</version> </dependency> -->

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${jsf.version}</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${jsf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-faces</artifactId>
            <version>${spring.webflow.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-webflow</artifactId>
            <version>${spring.webflow.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-binding</artifactId>
            <version>${spring.webflow.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>commons-logging</artifactId>
                    <groupId>commons-logging</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

        <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>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
    </dependencies>

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

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>
    <?xml version="1.0"?>
    <faces-config version="2.2" 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" metadata-complete="false" >

        <application>
            <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
            <!-- <resource-handler>org.omnifaces.resourcehandler.CombinedResourceHandler</resource-handler> -->
            <resource-handler>org.omnifaces.resourcehandler.UnmappedResourceHandler</resource-handler>


    </application>

    <lifecycle>
        <phase-listener>org.springframework.web.jsf.DelegatingPhaseListenerMulticaster</phase-listener>
    </lifecycle>

</faces-config>
<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="BeanManager" auth="Container"
        type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:pe="http://primefaces.org/ui/extensions">

<h:head>
</h:head>
<h:body>
    <p:panel>
         #{kpDisplay.hello}
     </p:panel>
</h:body>
</html>

@SpringBootApplication
@ComponentScan(basePackages={"com.kp.swasthik.bjsf"})
public class KpSbBjsfApplication extedns SpringBootServletInitializer{


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

     @Override
     protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(KpSbBjsfApplication.class);
  } 

  @Bean
public ServletRegistrationBean facesServletRegistration() {

    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new FacesServlet(), "*.xhtml");
    servletRegistrationBean.addUrlMappings("/faces/*");
    servletRegistrationBean.setLoadOnStartup(1);
    return servletRegistrationBean;
}

@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
    return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
}

@Bean
@ConditionalOnMissingBean
public RequestContextListener getRequestContextListener() {
    return new RequestContextListener();
}
}

和servlet上下文init类。

public class ServletCustmContextInitializer implements ServletContextInitializer {

    @Override
    public void onStartup(ServletContext jsfServlet) throws ServletException {
   jsfServlet.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
    jsfServlet.setInitParameter("javax.faces.PARTIAL_STATE_SAVING_METHOD", "true");
    jsfServlet.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
    jsfServlet.setInitParameter("facelets.DEVELOPMENT", "true");
    jsfServlet.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "1");
    jsfServlet.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
    jsfServlet.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
    jsfServlet.setInitParameter("primefaces.THEME", "bootstrap");

    }

}

我设法调出了jsf-Spring Boot配置,但现在JSF注释不起作用了。如果我手动将托管注释添加到faces-config.xml中,托管注释确实可以工作。我甚至添加了metadata-complete=“false”,所以jsf扫描注释,可惜它不起作用

暂时还没有答案

 类似资料:
  • 我有时会在pom中看到以下声明。xml。。。 如您所见,sping-boo-starter-web被声明为tomcat-embed-jasper。 是不是sping-boo-starter-web已经有一个嵌入式tomcat了?为什么一些开发人员仍然声明tomcat-embed-jasper以及boot-starter-web?还是有什么原因?

  • 问题内容: 我想制作一个桌面应用程序来浏览一个网站,我不想制作一个浏览器,而是一个浏览器嵌入的应用程序。我尝试过,但是发现了一些问题,例如缺少对插件的支持(例如:Flash,pdf查看器等)。 经过大量搜索后,我发现了Chromium嵌入式框架(CEF)或JCEF Java包装器,但我不知道如何在Java中使用它。 是否可以在Java应用程序中嵌入CEF / JCEF? 问题答案: 是否可以在Ja

  • 我在我的SpringBoot应用程序中使用下面提到的属性,在文件中让LDAP代码在我的本地机器上运行。 我想同时拥有我的嵌入式配置

  • 使用1.8。2--尝试(最初)设置2节点HA群集。 以下部分“22.5.4。启动Neo4j嵌入HA模式"的 http://docs.neo4j.org/chunked/stable/ha-setup-tutorial.html 我已将以下内容添加到我的pom中。xml: 并将我的application-content.xml修改如下: 和 /etc/白兔。属性包含: 节点1(地址:192.168.

  • 我使用springboot和jersey作为restful API。现在我想将swagger2集成到我的项目中,但它不起作用。当我运行我的应用程序并访问http://localhost:8080/swagger-ui.html.我得到了swagger网页,但没有显示api(见下图)。似乎swagger没有找到我的api类。 下面是我添加的依赖项。 以下是我的申请课程: 下面是我的jersey配置类

  • 我正在使用NetBeans IDE和带有Spring Boot的Maven。每当我运行我的应用程序不止一次,我就会得到这个错误: O.A.Coyote.http11.http11nioprotocol:无法启动与ProtocolHandler关联的终结点[“http-nio-8080”] spring boot java.lang.IllegalStateException:Tomcat连接器处于