我读到了有关使用
<context:component-scan base-package="tld.mydomain.business">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
并用 @Service("myService") 注释我的服务 bean,并且认为很好,我会这样做,因为我已经使用我的 Controller 这样做了。我通常的服务 bean 配置如下:
<bean id="userService" parent="txProxyTemplate">
<property name="target">
<bean class="tld.mydomain.business.UserServiceImpl"/>
</property>
<property name="proxyInterfaces" value="tld.mydomain.business.UserService"/>
</bean>
现在我生成了它们,如何将它们包装在 Hibernate 代理(例如 TransactionProxyFactoryBean)中?或者还有更好的方法吗?
我还没有完全使用@Repository,这是必需的吗?
干杯
尼克
最佳答案
在现代 Spring 应用程序中不鼓励使用 TransactionProxyFactoryBean,尽管它仍然有效。如今典型的方法是使用 @Transactional 注释类,然后将此元素粘贴到应用程序上下文文件中:
<tx:annotation-driven transaction-manager="txManager"/>
此策略和其他策略是 discussed引用文档中有很深入的内容,甚至还有关于 TransactionProxyFactoryBean 的旁注。
关于java - 从基于配置的服务 bean 切换到基于注释的服务 bean 时的 TransactionProxyFactoryBean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1632256/