Hibernate实体自动装配 [英] Hibernate entity autowire
问题描述
假设我有一个实体并希望在那里拥有邮件发件人,那么您可以请教我,我如何很好地为Hibernate实体启用Spring自动装配? :
@Entity
公共类EmailActivity延伸活动{
@Autowired @Transient
私人JavaMailSender javaMailSender;
...
}
有没有更好的方法(
AutowireCapableBeanFactory.autowireBean(
getCurrentSession().get(Activity.class,id)
);
在我的DAO中?
谢谢!
这是可能的! (它是Spring Roo中的默认样式!)
您需要的是将@Configurable注释添加到您的实体。激活配置< context:spring-configured />
并使用AspectJ交织的注释。
是Spring Reference中的一章: 7.8.1使用AspectJ向Spring依赖注入域对象
另请参阅:
顺便说一下,我强烈建议尽可能使用AspectJ编译时织入。
Can you please advice me, how can I nicely enable Spring autowiring for Hibernate entities?
Let's say I have an entity and would like to have mail-sender there:
@Entity
public class EmailActivity extends Activity {
@Autowired @Transient
private JavaMailSender javaMailSender;
...
}
Is there any better way than doing
AutowireCapableBeanFactory.autowireBean(
getCurrentSession().get(Activity.class, id)
);
in my DAO?
thanks!
It is possible! (And it is the default style in Spring Roo!)
All what you need is to add the @Configurable annotation to your Entity. Activate the annotation in the configuration <context:spring-configured/>
and using AspectJ weaving.
There is a Chapter in the Spring Reference: 7.8.1 Using AspectJ to dependency inject domain objects with Spring
See also:
- http://www.chrissearle.org/node/285
- http://www.olivergierke.de/wordpress/2009/05/using-springs-configurable-in-three-easy-steps/
BTW I strongly recommend to use AspectJ compile time weaving, when possible.
这篇关于Hibernate实体自动装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!