Summary

I have developed Spring Boot Application with Spring Security and mongodb. The application works in its embedded tomcat server. But while creating a war file and running it in tomcat. The Spring Boot application works fine, Spring Security Login mechanism works fine, the only issue is with the Spring security tags used in JSP. It throws the Exception with the cause:

Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.io.IOException: No visible WebSecurityExpressionHandler instance could be found in the application context. There must be at least one in order to support expressions in JSP 'authorize' tags. at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:663) at org.apache.jsp.WEB_002dINF.views.admin.sidebar_jsp._jspService(sidebar_jsp.java:167) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) ... 115 common frames omitted Caused by: java.io.IOException: No visible WebSecurityExpressionHandler instance could be found in the application context. There must be at least one in order to support expressions in JSP 'authorize' tags. at org.springframework.security.taglibs.authz.AbstractAuthorizeTag.getExpressionHandler(AbstractAuthorizeTag.java:210) at org.springframework.security.taglibs.authz.AbstractAuthorizeTag.authorizeUsingAccessExpression(AbstractAuthorizeTag.java:124) at org.springframework.security.taglibs.authz.AbstractAuthorizeTag.authorize(AbstractAuthorizeTag.java:96) at org.springframework.security.taglibs.authz.JspAuthorizeTag.doStartTag(JspAuthorizeTag.java:69) at org.apache.jsp.WEB_002dINF.views.admin.sidebar_jsp._jspx_meth_sec_005fauthorize_005f0(sidebar_jsp.java:187) at org.apache.jsp.WEB_002dINF.views.admin.sidebar_jsp._jspService(sidebar_jsp.java:144) ... 118 common frames omitted

JSP File Content StackTrace: 31-Jan-2020@11:37:19 ERROR: org.springframework.boot.web.servlet.support.ErrorPageFilter ==> Method : forwardToErrorPage ==> Forwarding to error page from request [/admin/home] due to exception [An exception occurred processing [WEB-INF/views/admin/sidebar.jsp] at line [16]

15: 
16:             <sec:authorize access="hasRole('ADMIN')">
17:                 <li class="has_sub"><a href="#" class="waves-effect"><i
18:                         class="ti-light-bulb"></i><span> Modules </span> </a>
19:                     <ul class="list-unstyled">

Stacktrace:] org.apache.jasper.JasperException: An exception occurred processing [WEB-INF/views/admin/sidebar.jsp] at line [16]

13:                         class="ti-home"></i> <span class="waves-effect">Home </span> </a></li>
14: 
15: 
16:             <sec:authorize access="hasRole('ADMIN')">
17:                 <li class="has_sub"><a href="#" class="waves-effect"><i
18:                         class="ti-light-bulb"></i><span> Modules </span> </a>
19:                     <ul class="list-unstyled">

Comment From: jzheaux

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

Feel free to update this issue with a link to the Stackoverflow question (so that other people can find it) or add more detail if you feel this is a genuine bug.