如何在单个可运行jar中部署spring boot jsf应用程序

如何在单个可运行jar中部署spring boot jsf应用程序,jsf,spring-boot,Jsf,Spring Boot,我有一个Spring Boot JSF应用程序,当从Netbeans IDE中启动时,它运行正常。当我将maven项目打包到一个可运行的jar中并询问URL时,我遇到了以下错误[java.lang.IllegalStateException:找不到factory javax.faces.context.FacesContextFactory的备份] 那么,在一个可运行的jar中部署spring boot jsf应用程序的正确方法是什么呢?我已经在互联网上搜索了4个小时,寻找解决方案。白费力气。我

我有一个Spring Boot JSF应用程序,当从Netbeans IDE中启动时,它运行正常。当我将maven项目打包到一个可运行的jar中并询问URL时,我遇到了以下错误[java.lang.IllegalStateException:找不到factory javax.faces.context.FacesContextFactory的备份]

那么,在一个可运行的jar中部署spring boot jsf应用程序的正确方法是什么呢?我已经在互联网上搜索了4个小时,寻找解决方案。白费力气。我已经找到了在Netbeans内部工作的解决方案,但当我从它们生成一个可运行的jar时,它们崩溃了

这是我的环境:

[web.xml]

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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-app_3_1.xsd">
  <!-- la servlet FacesServlet -->
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
</web-app>
[配置类]

    package web.config;

import config.MetierDaoJpaConfig;
import java.util.concurrent.TimeUnit;
import javax.faces.webapp.FacesServlet;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({MetierDaoJpaConfig.class})
@ComponentScan({"web.beans"})
// ******************************************************************************
// à utiliser conjointement avec [WEB-INF/faces-config.xml et WEB-INF/web.xml]
// ******************************************************************************
public class JsfConfig {

  @Bean
  public ServletRegistrationBean servletRegistrationBean() {
    FacesServlet servlet = new FacesServlet();
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet,"*.xhtml");
    return servletRegistrationBean;
  }

  @Bean
  public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    factory.setPort(8080);
    factory.setSessionTimeout(10, TimeUnit.MINUTES);
    return factory;
  }

}
[pom.xml]

<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>istia.st</groupId>
  <artifactId>mv-pam-primefaces-multipages-springboot-eclipselink-tomcat-02</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>mv-pam-primefaces-multipages-springboot-eclipselink-tomcat-02</name>
  <url>http://maven.apache.org</url>


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

  <dependencies>
    <!-- JSP API -->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    <!-- Spring web -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- JSF -->
    <dependency>
      <groupId>com.sun.faces</groupId>
      <artifactId>jsf-api</artifactId>
      <version>2.2.13</version>
    </dependency>
    <dependency>
      <groupId>com.sun.faces</groupId>
      <artifactId>jsf-impl</artifactId>
      <version>2.2.13</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
    <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <version>6.0</version>
    </dependency>

    <!-- JSR-330 --> 
    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <version>1</version>
    </dependency>

    <!-- couches basses -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>mv-pam-springboot-eclipselink</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>web.boot.Boot</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
</project>

4.0.0
伊斯提亚街
mv-pam-primefaces-multipages-springboot-eclipselink-tomcat-02
罐子
1.0-快照
mv-pam-primefaces-multipages-springboot-eclipselink-tomcat-02
http://maven.apache.org
org.springframework.boot
spring启动程序父级
1.4.0.1发布
org.apache.tomcat.embed
汤姆卡特·贾斯珀
org.springframework.boot
SpringBootStarterWeb
com.sun.faces
JSFAPI
2.2.13
com.sun.faces
jsf impl
2.2.13
org.primefaces
素面
6
javax.inject
javax.inject
1.
${project.groupId}
mv pam springboot eclipselink
${project.version}
org.apache.maven.plugins
maven surefire插件
2.18.1
maven汇编插件
web.boot.boot
带有依赖项的jar
UTF-8
1.8
1.8
    package web.config;

import config.MetierDaoJpaConfig;
import java.util.concurrent.TimeUnit;
import javax.faces.webapp.FacesServlet;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({MetierDaoJpaConfig.class})
@ComponentScan({"web.beans"})
// ******************************************************************************
// à utiliser conjointement avec [WEB-INF/faces-config.xml et WEB-INF/web.xml]
// ******************************************************************************
public class JsfConfig {

  @Bean
  public ServletRegistrationBean servletRegistrationBean() {
    FacesServlet servlet = new FacesServlet();
    ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet,"*.xhtml");
    return servletRegistrationBean;
  }

  @Bean
  public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    factory.setPort(8080);
    factory.setSessionTimeout(10, TimeUnit.MINUTES);
    return factory;
  }

}
<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>istia.st</groupId>
  <artifactId>mv-pam-primefaces-multipages-springboot-eclipselink-tomcat-02</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>mv-pam-primefaces-multipages-springboot-eclipselink-tomcat-02</name>
  <url>http://maven.apache.org</url>


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

  <dependencies>
    <!-- JSP API -->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    <!-- Spring web -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- JSF -->
    <dependency>
      <groupId>com.sun.faces</groupId>
      <artifactId>jsf-api</artifactId>
      <version>2.2.13</version>
    </dependency>
    <dependency>
      <groupId>com.sun.faces</groupId>
      <artifactId>jsf-impl</artifactId>
      <version>2.2.13</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
    <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <version>6.0</version>
    </dependency>

    <!-- JSR-330 --> 
    <dependency>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
      <version>1</version>
    </dependency>

    <!-- couches basses -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>mv-pam-springboot-eclipselink</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>web.boot.Boot</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
</project>