簡體   English   中英

使用Spring MVC集成測試時,Spring Security Taglib不可見

[英]Spring security taglib is not visible while using spring mvc integration tests

我正在嘗試使用MockMvc類進行一些“集成”測試

我用:

this.mockMvc.perform(
            get("/admin"))
                    .andExpect(status().isOk())
                    .andDo(print());

但是負責生成頁面的freemarker正在使用安全性taglib

 <#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />

Maven的依賴:

  <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>3.2.0.RELEASE</version>
    </dependency>

測試時似乎不可用。例外:

The following has evaluated to null or missing:
==> security  [in template "lib/abc.ftl" at line 170, column 19]

應用程序本身可以正常工作,但是我必須使用mvn tomcat:run-war而不是mvn tomcat:run來獲得taglib。

我不得不復制

~/.m2/repository/org/springframework/security/spring-security-taglibs/3.2.0.RELEASE/spring-security-taglibs-3.2.0.RELEASE.jar 

到我的WEB-INF / lib文件夾。 然后我遇到了另一個關於Missiong'Tag'類的問題,所以我不得不添加

 <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.2</version>
    </dependency>

復制粘貼該jar文件似乎是一種骯臟的解決方法..請讓我知道是否有更好的解決方案。

編輯

有一種使用mvn tomcat7:run而不是run-war來運行它的方法,因此可以在不重新啟動服務器的情況下加載taglib和刷新模板文件。 只需添加

<jarScanAllDirectoriescontextReloadable>true</jarScanAllDirectoriescontextReloadable>
<contextReloadable>true</contextReloadable>

到pom.xml中的tomcat7-maven-plugin

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM