LoginSignup
0
0

More than 5 years have passed since last update.

spring-securityのエラーメッセージが変更できない

Posted at

キーワード

「Bad Credential」から変わらない・・・

問題

Spring(Spring-Bootではない)に、spring-securityを導入して
ログイン認証を実装したところ、IDやパスに誤った入力をした際のエラー文言を出力するとデフォルトで設定されている文字しか出ないことで悩んでいました。

原因

MessageResourceのBean定義を
DispatcherServlet側(servlet-context.xml)で行なっていないでしょうか?

解決方法

ContextLoaderListner側(applicatinoContext.xml)で行うと動作しました。

原因の詳細

SpringでWebアプリケーションとして動作させる場合には
以下の2つのアプリケーションコンテキストを設定する必要がある。

  • ContextLoaderLister(親)
  • DispatcherServlet(子)

この2つは親子関係になっており、親が子のBeanを参照することはできるが逆はできない
なので、messageResourceを親でDIしてしまうと
spring-securityをDIしている子からは参照できないため発生してしまいます。

IMG_4263.JPG

参考

Springで開発を行う際には以下の大前提の知識がないと解決しづらいのでおさえておくといい

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0