Thymeleaf:Spring-Security:执行处理器'AuthorizeAttrProcessor'时出错

时间:2016-09-27 15:47:39

标签: spring-security thymeleaf

当我输入使用sec:authorize

的百万富翁页面时出现此错误
  

请求处理失败;嵌套异常是org.thymeleaf.exceptions.TemplateProcessingException:执行处理器'org.thymeleaf.extras.springsecurity4.dialect.processor.AuthorizeAttrProcessor'时出错   .....

     

根本原因

     

java.lang.IllegalStateException:找不到WebApplicationContext:没有注册ContextLoaderListener?

相关的依赖关系是:

	<properties>
		<spring.version>4.2.4.RELEASE</spring.version>
		<thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
	</properties>




				<!--  security -->
	 <dependency>
	      <groupId>org.springframework.security</groupId>
	      <artifactId>spring-security-web</artifactId>
	      <version>4.1.3.RELEASE</version>
	 </dependency>
	
	<dependency>
	    <groupId>org.thymeleaf.extras</groupId>
	    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
	    <version>2.1.2.RELEASE</version>
	</dependency>
	
	<dependency>
		<groupId>org.thymeleaf</groupId>
		<artifactId>thymeleaf-spring4</artifactId>
		<version>${thymeleaf.version}</version>
	</dependency>
       <dependency>
	   <groupId>org.thymeleaf</groupId>
	   <artifactId>thymeleaf</artifactId>
	   <version>${thymeleaf.version}</version>
      </dependency>

      <dependency>
	  <groupId>org.thymeleaf.extras</groupId>
	  <artifactId>thymeleaf-extras-tiles2-spring4</artifactId>
	  <version>2.1.1.RELEASE</version>
  </dependency>

相关的Thymeleaf代码是:

<div sec:authorize="isAuthenticated()">
		<a style="color:#555555" href="./logout" th:text="#{label.logout}">Logout</a>
</div>

相关的XML配置

        
            
    <!-- Thymeleaf Template Engine -->        
        <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.springsecurity4.dialect.SpringSecurityDialect"/>         
           </set>        
         </property>        
        </bean>        
            
            
   
任何建议都将非常感谢

1 个答案:

答案 0 :(得分:0)

答案是你需要在web.xml中指定Context Loader Listener.THis与thymeleaf无关。它只是spring config

&#13;
&#13;
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/*_applicationContext.xml</param-value>
</context-param>
&#13;
&#13;
&#13;

和听众:

&#13;
&#13;
 <listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
&#13;
&#13;
&#13;