ラベル Spring の投稿を表示しています。 すべての投稿を表示
ラベル Spring の投稿を表示しています。 すべての投稿を表示

2016年5月19日木曜日

Intellijでこんなエラーになりました。Could not autowire. No beans of TestMessagingTemplate type found

新しく定義した「@Component」を使用しようとしたら、Intellijでこんなエラーになりました。

Could not autowire. No beans of TestMessagingTemplate type found


調べたところ、新しく定義したコンポーネントがスキャンできてないが原因でした。

applicationContext.xmlファイルに、component-scanのパケージ場所を追加してあげれば問題を解決できます。
例:

<context:component-scan base-package="com.test.com.framework"/>

2015年6月7日日曜日

Spring Restfull APIで200 OKレスポンスを返す方法

関数にアノテーション「@ResponseStatus(HttpStatus.OK)」を追加
関数の返却値は「void」で定義する

例:
@RequestMapping(value = “/xxxx/{Id:.+}", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public void delete(@RequestHeader(“code") final String code, @PathVariable final String Id) throws ApplicationException{
    // 処理
    try {
        
    } catch (ApplicationException e) {
        
        }
    }
}

Spring Data JPAでselect IN-clause クエリーの使い方

Spring Data JPAでselect IN-clause クエリーの使い方


@Query(value = "SELECT * FROM User WHERE id IN (:ids)", nativeQuery = true)
Set<User> findByIdInSet(@Param("ids") Set<Long> ids);

2015年4月30日木曜日

spring security 自動ログイン

アカウント作成後、自動ログインセッションを作成するメソッドです。
  1. public static void updatePrincipal(UserDetails newPrincipal) {
  2. Authentication authentication = new UsernamePasswordAuthenticationToken(newPrincipal, null, (Collection) newPrincipal.getAuthorities());
  3. SecurityContextHolder.getContext().setAuthentication(authentication);
  4. }
  5.  

2015年4月13日月曜日

spring ログアウト処理

springのログアウトする方法がいつくがあります。

spring security でログアウト以外は、以下のやりかたもあります。

Spring Securityを使っていれば、以下を呼べばセッションをクリアにしてくれます。
    SecurityContextHolder.clearContext();

もしくは、明確的にセッションを消す

 if (invalidateHttpSession) {
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }
    }


SessionRegistry使うのも一つの選択かも
sessionRegistry.getSessionInformation(sessionId).expireNow();