JavaでSpringのメモ
@Transactional
トランザクション!
Springを使ってDBいじるなら@Transactionalが必要
しかしそれだけをメソッドにつけてもダメ
Spring構成ファイルに(xml)にアノテーションつけますよーって定義しないと
<tx:annotation-driven transaction-manager="transactionManager"/>
@Autowired
自動的にbeanをインジェクション!
しかしこれにも定義が必要
<context:annotation-config /> <context:component-scan base-package="jp.classmethod.sample.spring" />
でもSpring入れて
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional;
でもできるっぽい。
@Component
@Componentでインターフェースに対応するコンポーネントを作成
implementsするとxmlいらないって!
@Qualifier("ID名を指定できる")
@Autowiredを書くとき、インターフェースが1つでその実装クラスが2つあった場合、
ID名=インターフェース名にはできません。なのでこれでID名指定