Results 1 to 4 of 4

Thread: No transaction aspect-managed TransactionStatus in scope

  1. #1

    Default No transaction aspect-managed TransactionStatus in scope

    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--

    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)
    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.

    Any help would be great.

    Regards,
    Govinda
    Attached Images Attached Images

  2. #2
    Join Date
    Jun 2007
    Posts
    1

    Default

    Hi Govinda,
    Did you resolve the Exception ? I'm also getting the same Exception while using "Declarative transaction management" of Spring. I've followed all steps specified at http://www.springframework.org/docs/...on-declarative
    but dont know whats wrong. Is there any example on the net which I can check for Declarative /programmatic transaction management ? I've spend lot of time figuring out couldn't find a simple example showing how to use transaction management from Spring !!

  3. #3

    Default

    Mistake I did was I assumed that ApplicationContext, ClassPathResource, FileSystemResource for instantiating container can be used to develop enterprise applications (eg, which need transaction support).

    Java Applications need to use ApplicationContext which adds more functionality to BeanFactory than, FileSystemResource or ClassPathResource.

    WebApplications should use WebApplicationContext; but for WebApp you need to configure listeners and other classes in web.xml


    Hope that helps.....


    Regards,
    Govinda

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I think this information has made it into the new documentation for 2.1M3 so hopefully this will end this problem once and for all.
    Last edited by karldmoore; Aug 29th, 2007 at 12:07 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •