LucyとDBFluteの連携(その1)

コンストラクタインジェクションができたので、さっそく連携するためのテストを書いてみた。

@SingletonScope
public class BehaviorTest extends LucyTestCase {

	private Lucy lucy;
	
	public void setUp() throws Exception {
		lucy = getLucy();
		lucy.load("org/t2framework/samples/lucy/dbflute/config.xml");
	}
	
	public void testBehavior() throws Exception {
		final MemberCB cb = new MemberCB();
		MemberBhv memberBhv = lucy.get("memberBhv");
		memberBhv.selectList(cb);
	}
}

lucy-config.xmlは前回の日記の通り。
http://d.hatena.ne.jp/tan_go238/20090115



実行。そしてエラー!

java.lang.IllegalStateException: Look! Read the message below.
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Not found the invoker of behavior command as behavior's attributed!

[Advice]
Please confirm the definition of the invoker at your 'dbflute.dicon'.
It is precondition that 'createSelectListCBCommand()' needs the invoker instance.

[Your Behavior's Attributes]
  _behaviorCommandInvoker : null
  _behaviorSelector       : null
* * * * * * * * * */

_behaviorCommandInvoker, _behaviorSelectorがnullらしい。
なのでXMLのMemberBhvのところを少し修正してみる。

	<component name="memberBhv" class="org.t2framework.samples.todo.dbflute.exbhv.MemberBhv">
		<inject method="setBehaviorCommandInvoker">behaviorCommandInvoker</inject>
		<inject method="setBehaviorSelector">behaviorSelector</inject>
	</component>


すると・・・。

java.lang.NullPointerException
	at org.seasar.extension.jdbc.util.DataSourceUtil.getConnection(DataSourceUtil.java:48)
	at org.seasar.dao.impl.BeanMetaDataFactoryImpl.createBeanMetaData(BeanMetaDataFactoryImpl.java:91)
	at org.t2framework.samples.todo.dbflute.allcommon.s2dao.BeanMetaDataFactoryExtension.createBeanMetaData(BeanMetaDataFactoryExtension.java:52)
	at org.seasar.dao.impl.BeanMetaDataFactoryImpl.createBeanMetaData(BeanMetaDataFactoryImpl.java:83)
・・・

うーん。またしても違うところでNullPointerException。
どうやら最初のエラーにしてもこのエラーにしても、コンポーネントの自動登録ができていないのが問題みたい。
Lucyは基本的にDIするときはアノテーションか設定ファイルに書くのが原則なので、全部書くか何かしら自動登録する仕組みが必要みたい。


さすがに全部書くのは面倒なので、DBFluteとSpringではどうしてるのかなーとサンプルを見てみると、「s2dao-spring-0.1.0-SNAPSHOT.jar」の中にそれらしきクラスを発見。


しかし、どこで呼び出してどこでどのように使っているのかが分からない。。。



課題
・Lucyでコンポーネントの自動登録できるようにする。