Spring boot 很难让joinfaces项目设置服务于第一页

Spring boot 很难让joinfaces项目设置服务于第一页,spring-boot,joinfaces,Spring Boot,Joinfaces,我一直在努力学习关于使用primefaces的JSF的所有知识,我已经尝试设置我现有的spring boot应用程序,以便它通过使用joinfaces使用托管bean提供xhtml页面 我的问题是,首先,我的想法正确吗?(从下一段开始)我得到的例外是因为有重复导入的糟糕spring版本还是类似的东西 据我所知,我所需要的只是POM文件中的一些依赖项,以便joinfaces JSF Prime faces连接能够工作,以便使用它来设置spring启动应用程序,以及安全配置。我在下面列出了这些文件

我一直在努力学习关于使用primefaces的JSF的所有知识,我已经尝试设置我现有的spring boot应用程序,以便它通过使用joinfaces使用托管bean提供xhtml页面

我的问题是,首先,我的想法正确吗?(从下一段开始)我得到的例外是因为有重复导入的糟糕spring版本还是类似的东西

据我所知,我所需要的只是POM文件中的一些依赖项,以便joinfaces JSF Prime faces连接能够工作,以便使用它来设置spring启动应用程序,以及安全配置。我在下面列出了这些文件

就我所拥有的,我相信我应该点击url来激活src/main/resources/META-INF/resources文件夹中的login.xhtml页面

我没有看到登录页面出现-我得到了一个错误,似乎表明我有可能,错误的spring版本??(缺少标记化功能)

下面是login.xhtml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <f:view contentType="text/html">
        <h:head>
            <title>.:: Login JoinFaces Example ::.</title>
            <meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
            <link href="#{resource['images/favicon.ico']}" rel="shortcut icon"/>
            <h:outputStylesheet library="css" name="starter.css" />
        </h:head>
        <h:body>
            <pe:layout fullPage="true" >
                <pe:layoutPane position="center" >
                    <h:form prependId="false">
                        <div id="starterDiv" class="ui-fluid">
                            <center>
                                <p:outputLabel value="Connection failed: user and/or password are wrong." 
                                               rendered="${!empty param['error']}"/>
                                <p:focus />
                                <p:panelGrid columns="2" layout="grid">
                                    <h:outputText value="username" />
                                    <p:inputText id="username" />
                                    <h:outputText value="password" />
                                    <p:password id="password" />
                                </p:panelGrid>
                                <p:commandButton id="submit" value="Login" ajax="false" />
                            </center>
                        </div>
                    </h:form>
                </pe:layoutPane>
            </pe:layout>
        </h:body>
    </f:view>
</html>

您的SpringJAR版本不同步(如您所怀疑的)

根据日志,您的SpringWeb是
5.1.3.RELEASE
,我怀疑您的SpringCore版本可能是
5.1.2.RELEASE
或更低。请检查Maven依赖树/有效pom以进行验证

这是因为
spring启动程序父级:2.1.0.RELEASE
正在为spring依赖项添加
5.1.2.RELEASE
(请参阅),而bom
joinfaces依赖项添加
5.1.3.RELEASE
(请参阅)(覆盖一些托管spring版本)

有几种方法可以解决这个问题

  • 如果将Spring Boot父版本提升到
    2.1.1.RELEASE
    ,则应使Spring版本相同(因为它使用5.1.3.RELEASE),但问题可能会在以后提升版本时出现
  • 不要使用joinfaces bom表,让Spring引导父级管理正确的同步版本(如果您有Spring未管理的内容,您可以自己管理该版本)

谢谢helospark!正如您在版本中所怀疑的那样,这是正确的-我在5.1.3中使用了SpringWeb,在5.1.2中使用了SpringCore。我喜欢你的选择2的声音——尽管我不明白你在说什么。我正在尝试使用joinfaces使primefaces的“spring引导”变得简单-你是说我根本不应该包含joinfaces依赖项吗?我做了快速解决方案并尝试了选项1,它成功了-我得到了登录页面!请告诉我,你是怎么知道的?@Mike一般来说,NoSuchMethodException和Class(Def)NotFoundException表示依赖项不同步(Spring-deps应该始终同步)。通常,当您遇到这样的异常时,您应该检查API文档(在本例中:),并检查它是何时引入(或删除)的。然后,您只需确保包含包含此方法的依赖项版本。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <f:view contentType="text/html">
        <h:head>
            <title>.:: Login JoinFaces Example ::.</title>
            <meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
            <link href="#{resource['images/favicon.ico']}" rel="shortcut icon"/>
            <h:outputStylesheet library="css" name="starter.css" />
        </h:head>
        <h:body>
            <pe:layout fullPage="true" >
                <pe:layoutPane position="center" >
                    <h:form prependId="false">
                        <div id="starterDiv" class="ui-fluid">
                            <center>
                                <p:outputLabel value="Connection failed: user and/or password are wrong." 
                                               rendered="${!empty param['error']}"/>
                                <p:focus />
                                <p:panelGrid columns="2" layout="grid">
                                    <h:outputText value="username" />
                                    <p:inputText id="username" />
                                    <h:outputText value="password" />
                                    <p:password id="password" />
                                </p:panelGrid>
                                <p:commandButton id="submit" value="Login" ajax="false" />
                            </center>
                        </div>
                    </h:form>
                </pe:layoutPane>
            </pe:layout>
        </h:body>
    </f:view>
</html>
<?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.appzany.stockService</groupId>
    <artifactId>stock-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>stock-service</name>
    <description>Demo project for Spring Boot</description>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <joinfaces.version>4.0.1</joinfaces.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.joinfaces</groupId>
                <artifactId>joinfaces-dependencies</artifactId>
                <version>${joinfaces.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.joinfaces</groupId>
            <artifactId>security-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
          <groupId>org.joinfaces</groupId>
          <artifactId>primefaces-spring-boot-starter</artifactId>
        </dependency>

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

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.patriques</groupId>
            <artifactId>alphavantage4j</artifactId>
            <version>1.3-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
        </dependency>

        <dependency>
          <groupId>com.appzany</groupId>
          <artifactId>mathUtils</artifactId>
          <version>0.0.1-SNAPSHOT</version>
        </dependency>

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

    </dependencies>

    <build>

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


</project>
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) {
        try {
            http.csrf().disable();
            http
                .userDetailsService(userDetailsService())
                .authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers("/**.jsf").permitAll()
                .antMatchers("/javax.faces.resource/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login.jsf")
                .permitAll()
                .failureUrl("/login.jsf?error=true")
                .defaultSuccessUrl("/starter.jsf")
                .and()
                .logout()
                .logoutSuccessUrl("/login.jsf")
                .deleteCookies("JSESSIONID");
        }
        catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    @Override
    protected UserDetailsService userDetailsService() {
        InMemoryUserDetailsManager result = new InMemoryUserDetailsManager();
        result.createUser(User.withDefaultPasswordEncoder().username("persapiens").password("123").authorities("ROLE_ADMIN").build());
        result.createUser(User.withDefaultPasswordEncoder().username("nyilmaz").password("qwe").authorities("ROLE_USER").build());
        return result;
    }
}