没有web.xml的Spring Boot(jar)+ JSF

时间:2018-10-25 18:21:05

标签: java spring spring-boot jsf primefaces

我正尝试在不使用web.xml的情况下使用Spring Boot 2.0.5版和primefaces建立一个项目

当我输入http://localhost:8080/http://localhost:8080/product-list.jsf返回jsf页面时,我得到404。

看来我的控制器不起作用。

pom.xml

  

  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“>     4.0.0

     

com.auth0.samples     弹簧靴面     1.0快照罐
    spring-boot-faces春季启动   样品                       org.springframework.boot         弹簧启动启动器父母         2.0.5。发布

     

                              org.springframework.boot             spring-boot-starter-web

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

    <!-- JSF Dependency -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.9</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.9</version>
    </dependency>
          <!-- Tomcat Embed Dependency -->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

          <dependency>            <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-validation</artifactId>
  </dependency>
          <dependency>            <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>


  <!-- Database dependencies -->      <dependency>
      <groupId>org.hsqldb</groupId>           <artifactId>hsqldb</artifactId>
      <version>2.3.4</version>        </dependency>       <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-core</artifactId>            <version>4.1.2</version>
  </dependency>       <dependency>
      <groupId>org.ocpsoft.rewrite</groupId>
      <artifactId>rewrite-servlet</artifactId>
      <version>3.4.1.Final</version>      </dependency>       <dependency>
      <groupId>org.ocpsoft.rewrite</groupId>
      <artifactId>rewrite-integration-faces</artifactId>
      <version>3.4.1.Final</version>      </dependency>       <dependency>
      <groupId>org.ocpsoft.rewrite</groupId>
      <artifactId>rewrite-config-prettyfaces</artifactId>
      <version>3.4.1.Final</version>      </dependency>       <dependency>
      <groupId>org.primefaces</groupId>
      <artifactId>primefaces</artifactId>
      <version>6.1</version>      </dependency>               <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.16</version>      </dependency>   </dependencies>
     

                                 src / main / webapp                                                 src / main / resources                                                            org.springframework.boot                 spring-boot-maven-plugin                                                                                                重新包装                                                                             com.auth0.samples.bootfaces.Application                                                                                          

mainClass

@SpringBootApplication
public class Application{

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

    @Bean
    public ServletRegistrationBean<FacesServlet> facesServletRegistraiton() {
        ServletRegistrationBean<FacesServlet> registration = new ServletRegistrationBean<FacesServlet>(new FacesServlet(),
                new String[] { "*.jsf" });
        registration.setName("Faces Servlet");
        registration.setLoadOnStartup(1);

        return registration;
    }

    @Bean
    public ServletContextInitializer servletContextInitializer() {
        return servletContext -> {
            servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
        };
    }

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

}

控制器

@Scope (value = "session")
@Component (value = "productList")
@ELBeanName(value = "productList")
@Join(path = "/", to = "/product-list.jsf")
public class ProductListController {
    @Autowired
    private ProductRepository productRepository;
    private List<Product> products;
    @Deferred
    @RequestAction
    @IgnorePostback
    public void loadData() {
        products = productRepository.findAll();
    }
    public List<Product> getProducts() {
        return products;
    }
}

我找到了用于Spring Boot jsf集成的连接面,但是我不想向项目添加另一个依赖项。

反正有办法成功吗?

0 个答案:

没有答案