我正在尝试使用Spring @Configurable并将@AutowireDAO注入域对象,这样他们就不需要直接了解持久层了.
我正在尝试关注http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-atconfigurable,但我的代码似乎没有效果.
基本上,我有:
@Configurable
public class Artist {
@Autowired
private ArtistDAO artistDao;
public void setArtistDao(ArtistDAO artistDao) {
this.artistDao = artistDao;
}
public void save() {
artistDao.save(this);
}
}
Run Code Online (Sandbox Code Playgroud)
和:
public interface ArtistDAO {
public void save(Artist artist);
}
Run Code Online (Sandbox Code Playgroud)
和
@Component
public class ArtistDAOImpl implements ArtistDAO {
@Override
public void save(Artist artist) {
System.out.println("saving");
}
}
Run Code Online (Sandbox Code Playgroud)
在application-context.xml中,我有:
<?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>
Run Code Online (Sandbox Code Playgroud)
类路径扫描和初始化由弹簧模块执行Play!框架,虽然其他autowired …