Hi All,
I had a look at spring transactions and can get the annotation working for
the dao layer but not for the service layer?
This is the xml I added in the spring config file to enable spring
annotations (Java1.5+ required),
<!-- TRANSACTIONS -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCr
eator"/>
<bean
class="org.springframework.transaction.interceptor.TransactionAttributeSourc
eAdvisor">
<property name="transactionInterceptor" ref="txInterceptor"/>
</bean>
<bean id="txInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="txManager"/>
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttri
buteSource"/>
</property>
</bean>
Step 2, Tested it on the dao layer by modifying updateAccount
@Transactional
public void updateAccount(Account account) {
update("updateAccount", account);
int i = 5/0; //division by zero, expect rollback of account changes
update("updateProfile", account);
}
This works! But if I move the annotation to the service layer like this
@Transactional
public void updateAccount(Account account) {
accountDao.updateAccount(account);
}
I get
org.springframework.aop.framework.AopConfigException: Cannot proxy target
class because CGLIB2 is not available. Add CGLIB to the class path or
specify proxy interfaces.
Kind Regards
Meindert
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
Larry Meadors
Sent: 12 April 2007 04:14 PM
To: [EMAIL PROTECTED]
Subject: Re: converting iBATIS framework DAOs to the Spring Framework
Thanks a TON for doing this, it's really appreciated!
Here is the WIKI Page: http://tinyurl.com/ysvjw5
I just converted it to WIKI format and corrected some simple stuff.
I was curious why if we are starting with jpetshop5, why not use the
hsqldb stuff that is there?
Also, I'd suggest that we use constructor injection instead of setter
injection - that way, we only need to remove the default constructors
from the service classes (eg., public AccountService() {...}, and the
related imports. It also prevents people from replacing the dao
instances (well, not entirely, but they have to do a bit more work).
Larry