Spring boot taglibs

谁说胖子不能爱 提交于 2019-12-08 17:28:22

问题


I am using Spring boot.

I have a JSP page with the following tag libs:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>  
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

When loading my jsp page, I get the following error:

The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application

These are my POM dependencies:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</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-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

Any suggestions?


回答1:


I added following dependency:

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

Now it works.




回答2:


Add the following dependency

For : <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> :  

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


For : <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%> :

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



回答3:


Gradle users with Tomcat Plugin

If you are getting this error even if you have your dependency declared in gradle.build

runtime "org.springframework.security:spring-security-taglibs:${springSecurityVersion}"

And you are using the Tomcat plugin:

apply plugin: 'com.bmuschko.tomcat'

Then you MUST run the gradle tasktomcatRunWar instead of tomcatRun, so that the library is included in your servlet container.



来源:https://stackoverflow.com/questions/28560311/spring-boot-taglibs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!