2016-09-27 48 views
1

當我輸入利用秒thymeleaf頁面我得到這個錯誤:授權Thymeleaf:彈簧安全:處理器的執行過程中的錯誤「AuthorizeAttrProcessor」

請求處理失敗;嵌套異常是org.thymeleaf.exceptions.TemplateProcessingException:處理器的 'org.thymeleaf.extras.springsecurity4.dialect.processor.AuthorizeAttrProcessor' 執行期間的錯誤.....

根源

java.lang中.IllegalStateException:找不到WebApplicationContext:沒有註冊ContextLoaderListener?

相關依賴關係是:

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

 

 

 

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

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

相關Thymeleaf代碼是:

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

相關的XML configuuration是

  
 
      
 
    <!-- 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>   
 
      
 
      
 
任何建議,將不勝感激

回答

0

答案是,你需要指定上下文加載器監聽器在web.xml.THis是不是與thymeleaf有關。這只不過是Spring配置

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

和聽衆:

<listener> 
 
    <listener-class> 
 
     org.springframework.web.context.ContextLoaderListener 
 
    </listener-class> 
 
</listener>