我正在实现Spring Security&我有一个自定义登录表单,例如:
<c:if test="${not empty param.error}">
<div class="errorblock">
LOGIN ERROR<br/>
Reason: ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}<br/>
</div>
</c:if>
<form method="POST" action="<c:url value="/j_spring_security_check"/>">
...
</form>
到目前为止,到目前为止,显示的原因与预期的一样(即,如果我的数据库已关闭,则为
Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin failed
)我希望能够显示更加用户友好的消息,例如“数据库问题,请联系管理员”
我尝试将
typeMismatch.org.hibernate.TransactionException=Unable to connect to databse, please contact an admin
添加到我已用于覆盖Spring安全身份验证异常的messages.properties
中,请参阅how to display custom error message in jsp for spring security auth exception我不太确定如何“调用”此自定义错误消息。
谢谢你的帮助。
最佳答案
您引用的线程中的方法仅在您想要更改现有Spring消息的消息时才起作用,您可以在安全核心jar内的message.properties文件中看到该消息。因此,这对您要尝试执行的操作无效。您可以将发生故障的操作定向到另一个 Controller (请参阅authentication-failure-url),并在该处执行任何所需的自定义错误处理,然后显示登录表单 View ,该 View 显示您生成的消息。
关于spring - Spring Security,自定义登录表单: display custom message matching SPRING_SECURITY_LAST_EXCEPTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973984/