【Spring Security】認証エラー時に独自のJSONを返す方法
![Thumbnail of post image 090](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
Spring MVCで作成したRest APIに対するリクエストが認証エラーとなった際に独自のJSONをレスポンスとして返すようにします。
認証はリクエストのAuthorizationヘッダ中のトークンを使用し ...
How to create custom validations in Spring MVC
![Thumbnail of post image 057](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
In Spring MVC, @AssertTrue annotation helps us to create custom validat ...
【Spring】Spring MVCでのWeb APIの作り方まとめ
![Thumbnail of post image 188](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
Spring MVCでWeb APIを作る際には@RestControllerアノテーションを使用するのが一般的です。@RestControllerをコントローラクラスに付与します。@RestControllerを付 ...
【Java】Spring SecurityのCORS設定で許可するオリジンを環境変数から読み込む
![Thumbnail of post image 146](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
以下の記事で作成したSpring SecurityのCORS設定に対して、アクセスを許可するオリジンを環境変数から読み込む処理を追加します。
【Java】Spring Secu ...【Java】Spring SecurityにCORS設定を追加する
![Thumbnail of post image 163](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
以下の記事で作成したSpring Securityを使用しWeb APIのリクエストごとにトークンで認証する処理にCORS設定を追加します。
【Spring】Spring Sec ...【Java】HmacUtilsを使ってHMACメッセージダイジェストを生成する
![Thumbnail of post image 117](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
Apache Commons Codecで提供されているHmacUtilsクラスを利用することでメッセージダイジェストを簡単に生成することができます。
公式 ...
【Java】How to generate a static factory method with @AllArgsConstructor of Lombok
![Thumbnail of post image 039](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
@AllArgsConstructor generates an all-args constructor for ...
【Spring】MockMvc + AssertJでREST APIのテスト
![Thumbnail of post image 135](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
この記事ではSpring MVCの@RestControllerを使用し作成したREST APIのレスポンスをMockMVC使用してテストする際に、AssertJを使用してAP ...
【Java】Guavaのファクトリメソッドを使ったArrayLsitの生成方法
![Thumbnail of post image 124](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
GuavaのListsクラスに用意されているファクトリメソッドを使用することでArrayListのインスタンス生成と初期値の設定を以下のように簡潔に記述することができます。
【Java】Guavaを使ってロウワスネークケースをロウワーキャメルケースへ変換する
![Thumbnail of post image 040](https://sebenkyo.com/wp/wp-content/uploads/2020/02/programming1-150x150.jpg)
Spring BootプロジェクトでDBなどでよく使われるロウワーキャメルケース(例: user_name)の文字列をJavaの変数名でよく使われるロウワーキャメルケースへ変換する。
Guavaを使えば簡単Guava ...