Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未找到spring security TILEAF页404_Java_Spring Mvc_Spring Security_Tiles_Thymeleaf - Fatal编程技术网

Java 未找到spring security TILEAF页404

Java 未找到spring security TILEAF页404,java,spring-mvc,spring-security,tiles,thymeleaf,Java,Spring Mvc,Spring Security,Tiles,Thymeleaf,我已经配置了SpringMVC和theymeleaf和tiles,并且工作正常,现在我正在尝试将SpringSecurity与它们集成 但问题是: 1.当应用程序在登录页面启动并输入用户名和密码时,没有响应(即它从不调用控制器)(我使用了System.out.println(“调用”);但登录方法中没有打印任何内容) 2.当我尝试访问另一个页面时,它会重定向到登录页面,但找不到它,并给出404 not found 有人能告诉我我的配置哪里出了问题吗 springservlet <mvc:a

我已经配置了SpringMVC和theymeleaf和tiles,并且工作正常,现在我正在尝试将SpringSecurity与它们集成
但问题是:
1.当应用程序在登录页面启动并输入用户名和密码时,没有响应(即它从不调用控制器)(我使用了
System.out.println(“调用”);
但登录方法中没有打印任何内容)
2.当我尝试访问另一个页面时,它会重定向到登录页面,但找不到它,并给出404 not found

有人能告诉我我的配置哪里出了问题吗

springservlet

<mvc:annotation-driven />
    <context:annotation-config />
    <context:component-scan base-package="org.gaca.gms.controllers" />

    <bean id="templateResolver" 
                class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
                <property name="prefix" value="/WEB-INF/" />
                <property name="suffix" value=".html" />
                <property name="characterEncoding" value="UTF-8" />
                <property name="templateMode" value="HTML5" />
    </bean>

        <bean id="tilesConfigurer" 
                class="org.thymeleaf.extras.tiles2.spring4.web.configurer.ThymeleafTilesConfigurer">
                <property name="definitions">
                        <list>
                                <value>/WEB-INF/tiles-defs.xml</value>
                        </list>
                </property>
        </bean>

        <bean id="tilesViewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
                <property name="viewClass" 
                        value="org.thymeleaf.extras.tiles2.spring4.web.view.ThymeleafTilesView" />
                <property name="templateEngine" ref="templateEngine" />
                <property name="characterEncoding" value="UTF-8" />
                <property name="order" value="1" />
                <property name="viewNames" value="templates/*,pages/*,redirect*,loginView" />
        </bean> 
        <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
                <property name="templateResolver" ref="templateResolver" />
                <property name="additionalDialects">
                        <set>
                                <bean class="org.thymeleaf.extras.tiles2.dialect.TilesDialect" />
                                 <bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
                        </set>
                </property>
        </bean>

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" />


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.connection.useUnicode">true</prop>
                <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>
            </props>
        </property>
    </bean>

    <bean id="usersService" class="org.gaca.gms.services.GenericServiceImpl"></bean>
    <!-- <bean id="loginService" class="org.gaca.gms.services.GenericServiceImpl"></bean> -->
    <bean id="genericDAO" class="org.gaca.gms.dao.GenericDAOImpl"></bean>
    <bean id="loginController"
    class="org.springframework.web.servlet.mvc.ParameterizableViewController">
    <property name="viewName" value="loginView" />
   </bean>
    <tx:annotation-driven />
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
登录页面

<!DOCTYPE html>
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
  <div sec:authentication="name"/> 

        <h1>Login page</h1>
        <p th:if="${loginError}">Wrong user or password</p>
        <form th:action="@{/j_spring_security_check}" method="post">
            <label for="j_username">Username</label>:
            <input type="text" id="j_username" name="j_username" /> <br />
            <label for="j_password">Password</label>:
            <input type="password" id="j_password" name="j_password" /> <br />
            <input type="submit" value="Log in" />
        </form>
</div>

登录页面

错误的用户或密码

用户名:
密码:

在Spring安全设置中,您似乎正在使用
/loginView
作为登录页面,但您的控制器正在定义
/Spring\u Security\u login
。这些不应该匹配吗?@CodeChimp我确实试过了,正如你评论的那样,但没有任何改变。你能在你的控制器中打印出来,看看它是否走得那么远吗?我想你会发现它不是。@CodeChimp是的,我按照我在问题中说的那样做了。它不调用控制器。在这个例子中,它们只有一个
标记,并且权限设置为
权限
 <global-method-security pre-post-annotations="enabled" />

      <http pattern="/loginView" security="none"/>

    <http use-expressions="true">
        <intercept-url pattern="/resources/**" access="permitAll" />
        <intercept-url pattern="/templates/**" access="permitAll" />
        <intercept-url pattern="/pages/**" access="hasAuthority('User')" />
        <intercept-url pattern="/pages/admin/**" access="hasRole('Admin')"/>

          <form-login login-page="/loginView" authentication-failure-url="/loginView" default-target-url="/pages/usersView" always-use-default-target='true'/>

        <remember-me />
  </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
              <user name="admin" password="123" authorities="Admin,User" />
              <user name="user" password="111" authorities="User" />
             </user-service>
        </authentication-provider>
    </authentication-manager>
@RequestMapping("/spring_security_login")
    public String login() {
        System.out.println("calling login");
        return "loginView";
    }

   // Login form with error
    @RequestMapping("/spring_security_login")
    public String loginError(Model model) {
        model.addAttribute("loginError", true);
        return "loginView";
    }
<!DOCTYPE html>
<div xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
  <div sec:authentication="name"/> 

        <h1>Login page</h1>
        <p th:if="${loginError}">Wrong user or password</p>
        <form th:action="@{/j_spring_security_check}" method="post">
            <label for="j_username">Username</label>:
            <input type="text" id="j_username" name="j_username" /> <br />
            <label for="j_password">Password</label>:
            <input type="password" id="j_password" name="j_password" /> <br />
            <input type="submit" value="Log in" />
        </form>
</div>