I am using Spring 2.0 framework, and spring IDE eclipse plugin.
Please do have a look at the attached JPG file. Spring IDE shows (and I think)that I have properly coded spring bean config file.
Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <!-- <bean/> definitions here --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/soadb2"></property> <property name="username" value="root"></property> <property name="password" value="helloworld"></property> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <constructor-arg> <ref bean="dataSource"></ref> </constructor-arg> </bean> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="myStoredProcedure" class="springexample.services.MyStoredProcedure"> <constructor-arg> <ref bean="dataSource"></ref> </constructor-arg> </bean> <bean id="fooService" class="springexample.services.FooService"> <constructor-arg> <ref bean="myStoredProcedure"/> </constructor-arg> </bean> <tx:advice id="txAdvice" transaction-manager="txManager" > <tx:attributes> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="fooServiceOperation" expression="execution (* springexample.services.FooService.*())"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation" /> </aop:config> </beans>
Code:public class FooService { MyStoredProcedure myProc; public FooService(MyStoredProcedure myProc) { this.myProc = myProc; } public int generatePrimaryKey() { //MyStoredProcedure myProc = (MyStoredProcedure)MainClass.factory.getBean("myStoredProcedure"); Map results = myProc.execute(); Integer primKey = (Integer)results.get("primKey"); TransactionStatus status = TransactionAspectSupport.currentTransactionStatus(); System.out.println("Before executing set rollbackOnly"); status.setRollbackOnly(); System.out.println("After executing set rollbackOnly"); return primKey.intValue(); } }
In eclipse I got following stack trace--
I am using MySQL 5.0 as DB. There were some concerns raised by developers that InnoDB should be running. I confirmed that is running.
May 8, 2007 11:42:33 AM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans-config.xml]
May 8, 2007 11:42:33 AM org.springframework.jdbc.datasource.DriverManagerD ataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Exception in thread "main" org.springframework.transaction.NoTransactionExcep tion: No transaction aspect-managed TransactionStatus in scope
at org.springframework.transaction.interceptor.Transa ctionAspectSupport.currentTransactionStatus(Transa ctionAspectSupport.java:106)
at springexample.services.FooService.generatePrimaryK ey(FooService.java:27)
at springexample.MainClass.main(MainClass.java:41)
Any help would be great.
Regards,
Govinda


Reply With Quote