spring 问题:

zzzbbbll0304 2004-09-06 05:21:55
spring 如果使用jtaTransactionManager 做 分布式事务,必须要梆定到应用服务器吗。如weblogic?
还是在Tomcat 里,把jotm 的jar 放进 common/lib,做些配置就可以了?

在单个数据源的情况下,我用的TransManager 是DatasourceTransactionManager
现在要用分布式事务,即只需要把配置文件的TransManager 的Class 属性 改成 JtaTransactinManager 就可以了吗??以前 用jdbcTemplate 做数据操作的代码都不用变,是吗?

spring 真的真的这么牛吗?迷惑。
...全文
186 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzzbbbll0304 2004-09-08
  • 打赏
  • 举报
回复
如果用jotm 来做分布式的事务,是不需要的appserver 的。
而 jotm 是兼容 jta 的。这又如何解释呢。
spring 用的也是jotm 呀。
很少出现不代表没有。
niyboy 2004-09-08
  • 打赏
  • 举报
回复
我也正在学习;

我帮你顶;

也学习学习
廖雪峰 2004-09-07
  • 打赏
  • 举报
回复
JTA一般都是app server提供的,如果不用app server只用jta(我觉得这种情况很少出现,所以spring说JTA is normally only available in an application server environment.),那就考虑实现了jta但不是app server的JOTM
zzzbbbll0304 2004-09-07
  • 打赏
  • 举报
回复
Spring's transaction management capabilities--and especially its declarative transaction management--significantly changes traditional thinking as to when a J2EE application requires an application
server.

In particular, you don't need an application server just to have declarative transactions via EJB. In fact, even if you have an application server with powerful JTA capabilities, you may well decide that Spring declarative
transactions offer more power and a much more productive programming model than EJB CMT.

You need an application server's JTA capability only if you need to enlist multiple transactional resources.Many applications don't face this requirement. For example, many high-end applications use a single, highly
scalable, database such as Oracle 9i RAC.

Of course you may need other application server capabilities such as JMS and JCA. However, if you need only JTA, you could also consider an open source JTA add-on such as JOTM. (Spring integrates with JOTM out of
the box.) However, as of early 2004, high-end application servers provide more robust support for XA transactions.

The most important point is that with Spring you can choose when to scale your application up to a full-blown application server. Gone are the days when the only alternative to using EJB CMT or JTA was to write coding using local transactions such as those on JDBC connections, and face a hefty rework if you ever needed that code to run within global, container-managed transactions. With Spring only configuration needs to change: your code doesn't.



这是文档:

if you need only JTA, you could also consider an open source JTA add-on such as JOTM. (Spring integrates with JOTM out of
the box.)

这句话的具体是什么意思。
林仪明 2004-09-07
  • 打赏
  • 举报
回复
mark
廖雪峰 2004-09-07
  • 打赏
  • 举报
回复
附:
Furthermore, a JTA UserTransaction normally needs to be obtained from JNDI: meaning that we need to use both JNDI and JTA to use JTA. Obviously all use of global transactions limits the reusability of application code, as JTA is normally only available in an application server environment.

(Spring Framework Version 1.1, page 70)
廖雪峰 2004-09-07
  • 打赏
  • 举报
回复
根据spring的文档:(我只看了官方文档,没有深入研究)

只要是分布式事务,即有多个数据源,必须用jta,而管理分布式事务必须需要一个app server(weblogic, jboss...),也就是说global transaction必须邦定到app server的jndi,spring自己并不能创建只是负责查询jndi得到jta
niyboy 2004-09-07
  • 打赏
  • 举报
回复
正在研究;

帮你顶
zzzbbbll0304 2004-09-06
  • 打赏
  • 举报
回复
<bean id="business" class="com.bjhuajia.silver.Business">
<property name="transactionManager">
<ref local="transactionManager" />
</property>
</bean>



在 bussiness layer 控制事务

public class business{
public void doWork(Info Info) {
JdbcTemplate jt = new JdbcTemplate();
jt.update("insert into Vender (venderName) values ('asdfa')");
jt.update("insert into Agreement(agreementName) values ('asdfas");
}




Business bs = (Business) factory.getBean("business");
bs.doWork(info);

晕了:大概是这样做吗。哪位知道:

spring 的分布式事务 必须要梆钉 到 appserver 才有效吗。疑惑
如果干用jotm 做 分布式事务的话,也不需要appserver 啊。 直接在tomcat 就可以了。
我看 spring 也是用的 jotm 的吗。




zzzbbbll0304 2004-09-06
  • 打赏
  • 举报
回复
asklxf(xuefeng):
你的意思还是单个数据源下的情况:只不过是用jtaTransactionManager 来控制事务罢了,那样 程序式事务 也是不用改变代码的。其实这还是 localTransactions


但是我的意思是:如果用jtaTransactionManager,那就要是 globalTransactions 了。就是说是两个数据源 两个连接,执行的是两阶段提交:

如:

bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction"><ref local="jotm"/></property>
</bean>

<bean id="globalDataSource1" class="org.enhydra.jdbc.standard.StandardXADataSource">
<property name="driverName">...</property>
<property name="url">url1</property>
</bean>

<bean id="globalDataSource2" class="org.enhydra.jdbc.standard.StandardXADataSource">
<property name="driverName">...</property>
<property name="url">url2</property>
</bean>

比如我现在有两张表:vender 和 agreement 两个表:

vender 在 globalDataSource1 里
agreement 在 globalDataSource2 里



<bean id="venderDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

<property name="transactionManager">
<ref bean="transactionManager" />
</property>

<property name="target">
<ref local="venderDAO" />
</property>

<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>

</bean>

<bean id="venderDAO" class="com.bjhuajia.silver.dao.ExtDao">
<property name="dataSource">
<ref local="globalDataSource1" />
</property>

<property name="transactionManager">
<ref local="transactionManager" />
</property>
</bean>


<bean id="agreemnentDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

<property name="transactionManager">
<ref bean="transactionManager" />
</property>

<property name="target">
<ref local="agreementDAO" />
</property>

<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>

</bean>

<bean id="agreementDAO" class="com.bjhuajia.silver.dao.AgreementDao">
<property name="dataSource">
<ref local="globalDataSource2" />
</property>

<property name="transactionManager">
<ref local="transactionManager" />
</property>
</bean>

<bean id="BusinessProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>

<property name="target">
<ref local="business" />
</property>

<property name="transactionAttributes">
<props>
<prop key="do*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>


在 bussiness layer 控制事务

public class business{


廖雪峰 2004-09-06
  • 打赏
  • 举报
回复
根据spring的文档:

global transaction是由app server管理,使用jta

如果你在spring中使用申明式的事务,那么可以很方便的在jta和local transaction之间转换,不用改代码
wilsonkun 2004-09-06
  • 打赏
  • 举报
回复
bu zhi dao

up
NewTypeQ 2004-09-06
  • 打赏
  • 举报
回复
没用过spring的jta,也想知道!

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧