Announcement Announcement Module
Collapse
No announcement yet.
@Transactional and GenericApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @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
    Not sure what you want but hte instance is the proxy...

    Comment


    • #3
      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, 04:06 AM.

      Comment


      • #4
        If there is no proxy your configuration is wrong... Also you should first refresh the applicationcontext instead of directly getting the beans.

        Comment


        • #5
          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"/>

          Comment


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

            Comment

            Working...
            X