gpt4 book ai didi

java - Spring 中 @Transactional 相对于 ProxyFactoryBean 的性能

转载 作者:行者123 更新时间:2023-11-30 06:33:14 25 4
gpt4 key购买 nike

在我的应用程序中,我最初使用 ProxyFactoryBean 将事务应用到我的 DAO Bean,如下所示;

<bean id="buyProductDAO" class="com.trading.persistence.impl.jdbc.BuyProductDAOImpl" scope="prototype">
<property name="jdbcTemplate">
<ref bean="jdbcTemplate"/>
</property>
</bean>

<bean id="buyProductDAOProxy" class="org.springframework.aop.framework.ProxyFactoryBean" scope="singleton">
<property name="proxyInterfaces">
<value>com.trading.persistence.impl.jdbc.BuyProductDAO</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
<value>buyProductDAO</value>
</list>
</property>
</bean>

在这种情况下,如果我从代码中发现代理 bean,它将返回我事务 bean。此外,目前,交易适用于类(class)级别。

我想重构我的代码以使用@Transactionl。转换后会对性能产生什么影响?我计划在方法级别应用事务,与当前实现的类级别相反。

最佳答案

直接使用ProxyFactoryBean作为Spring中声明式事务管理的一种方式是一种非常古老的风格,不再需要了。

From the Spring Documentation :

Where is TransactionProxyFactoryBean?

Declarative transaction configuration in versions of Spring 2.0 and above differs considerably from previous versions of Spring. The main difference is that there is no longer any need to configure TransactionProxyFactoryBean beans.

The pre-Spring 2.0 configuration style is still 100% valid configuration; think of the new as simply defining TransactionProxyFactoryBean beans on your behalf.

看来你已经喜欢Declarative over Programmatic Transaction Management了(这几乎是当今的标准)因此没有理由不完全接受 @Transactional 划分风格。

关于java - Spring 中 @Transactional 相对于 ProxyFactoryBean 的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45659365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com