私はSpringの@Configurable
と@Autowire
を使用してドメインオブジェクトにDAOを注入し、パーシスタンスレイヤーを直接知る必要はないと考えています。@Configurableを使用した春のオートワイヤリング
私はに従おうとしていますが、私のコードは効果がないようです。
基本的に、私が持っている:
@Configurable
public class Artist {
@Autowired
private ArtistDAO artistDao;
public void setArtistDao(ArtistDAO artistDao) {
this.artistDao = artistDao;
}
public void save() {
artistDao.save(this);
}
}
そして:
public interface ArtistDAO {
public void save(Artist artist);
}
およびアプリケーションのcontext.xmlで
@Component
public class ArtistDAOImpl implements ArtistDAO {
@Override
public void save(Artist artist) {
System.out.println("saving");
}
}
、私が持っている:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springsource.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
<bean class="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect" factory-method="aspectOf"/>
</beans>
クラスパスのスキャンと初期化は、Play!のスプリングモジュールによって実行されます。フレームワークは、他のautowired豆が動作しますが、私はこれが根本的な原因ではないと確信しています。私はSpring 3.0.5を使用しています。他のコードで
(実際には春を使用して、私のコントローラに注入していますBean内のメソッド内で)、私はこれをやっている:
Artist artist = new Artist();
artist.save();
これは私のアーティストでartistDaoにアクセスしようとするとNullPointerExceptionを与えます。セーブ()。
私が間違っていることを知っていますか?マーティン
関連;)http://techblog.bozho.net/?p=180は – Bozho
あなたは 'Configurable' @で[値]注釈@'使用することはできますが、クラスのアーティストをマーク? – NightWolf