Results 1 to 6 of 6

Thread: @Transactional and GenericApplicationContext

  1. #1
    Join Date
    Nov 2012
    Posts
    11

    Question @Transactional and GenericApplicationContext

    Hi all,

    At the beginning I want to say hello for everyone, because I'm new at this forum.

    And now to the point:

    I'm using @Transactional and transaction management by annotation (<tx:annotation-driven>). I have problem when I'm using GenericApplicationContext to create application context and get some beans from it:
    Code:
    GenericApplicationContext ctx = new GenericApplicationContext();
    			
    			// Load beans definitions 
    			XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    			xmlReader.loadBeanDefinitions(new ClassPathResource(CONTEXT_PATH));
    			
    			// Register the datasource 
    			ctx.getBeanFactory().registerSingleton(CONTEXT_DATASOURCE_BEAN_NAME, dataSource);
    			
    			// Get the service
    			ServiceInterface service = (ServiceInterface) ctx.getBean("service");
    I've got the instance of ServiceInterface but I want to have the proxy which contains information about transactions.

    Could you explain me what I've missed?

    Thanks for your help

    Regards Tomasz

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Not sure what you want but hte instance is the proxy...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2012
    Posts
    11

    Default

    Did you get the "service" as a proxy? I have it as a instance of the Service class. I don't have any information about the transactions :/

    Basically my problem is very similar to: http://forum.springsource.org/showth...-via-a-factory

    I want to have transactions on beans created by bean factory. How to proceed transaction annotation after getting bean from bean factory?
    Last edited by master_on; Nov 6th, 2012 at 03:06 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    If there is no proxy your configuration is wrong... Also you should first refresh the applicationcontext instead of directly getting the beans.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Nov 2012
    Posts
    11

    Default

    Thanks for your replies. So do you have any idea what can be missed in configuration? I have only this for transactions:
    Code:
         <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
            	<ref local="sessionFactory"/>
            </property>
        </bean>
        
        <!-- enable the configuration of transactional behavior based on annotations -->
    	<tx:annotation-driven transaction-manager="txManager"/>

  6. #6
    Join Date
    Nov 2012
    Posts
    11

    Default

    Thank you very much Marten. I've added ctx.refresh() and now I have proxy.

Tags for this Thread

Posting Permissions

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