Announcement Announcement Module
Collapse
No announcement yet.
Setting up AOP programatically Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting up AOP programatically

    How can I set ut AOP proxying programatically? My application has many services and to minimize the users need to set up a large context I have created a factory which the user can get all the services from.

    This factory will set up all the dependencies it self, but I do not know how to set up the transaction injection in my factory.

    Each service uses a wrapper class to access the database and HibernateTemplate. When I do not use the factory I have set up this wrapper class in the context as a ProxyFactoryBean which uses interceptorNames which points to a TransactionInterceptor which uses a HibernateTransactionManager.

    How can I set up this complex network of AOP transaction programatically in my factory?

  • #2
    Why would you have to use a ProxyFactoryBean?! With Spring 2.0 and 2.5 you can use the aop:config blocks which automatically creates proxies for you. Even better/simpler when you use annotations and Spring 2.5 the only thing you need is 2 lines of xml.

    IMHO you are making it way to complex for yourself...

    Comment


    • #3
      Originally posted by mdeinum View Post
      Why would you have to use a ProxyFactoryBean?! With Spring 2.0 and 2.5 you can use the aop:config blocks which automatically creates proxies for you. Even better/simpler when you use annotations and Spring 2.5 the only thing you need is 2 lines of xml.

      IMHO you are making it way to complex for yourself...
      The idea is to use the factory so that those who use this code does not need to set up a huge context. They only need to configure my Factory bean. This is a self created factory.

      However I choose to configure the wrapper class that uses transaction(Spring 1 or 2) I would need to set it up in my factory class programatically.

      Comment


      • #4
        The fact that you use a factory doesn't mean that you cannot create a ApplicationContext yourself (which is only used by your factory bean), that would save you a lot of trouble and time, that way you could still use the features of spring instead of re-inventing them yourself....

        Comment


        • #5
          If you are unable to use annotation based configuration (which gives you a 2 line config, as mdeinum said), you can also distribute a context that your clients only have to include that context and not care about configuring it.

          I think that using Spring, but getting rid of the declarative configuration is negating part of the advantage of Spring ...

          And to go back to your initial idea of setting up AOP programatically : I have no idea ...

          Comment


          • #6
            A TransactionManager needs a DataSource and my project is not supposed to configure a datasource, the client is.

            By letting the client set the dataSource and not setting it in the factory application context would need to set it programatically. If I configure a fully functional application context with a reference to a dataSource and the client configures the dataSource in its application context then the factory application contex will not find the datasource bean.

            This problem probably occours because the application context opened in the factory does not know of the application context of the client that created the datasource and factory bean. How can I go around this?
            Last edited by DJViking; Feb 11th, 2008, 05:51 AM.

            Comment


            • #7
              I still see no reason why you cannot use an application context. Initialize it AFTER that the client has set it's DataSource, register that programmatically in your ApplicationContext (or create an app context that contains only the datasource and register that as the parent!) and do your stuff. That way the only programmatic stuff you need to do is register the datasource...

              Hmm maybe even better, let the client register their application context with your Factory and use that as a parent context...

              Comment


              • #8
                Originally posted by mdeinum View Post
                I still see no reason why you cannot use an application context. Initialize it AFTER that the client has set it's DataSource, register that programmatically in your ApplicationContext (or create an app context that contains only the datasource and register that as the parent!) and do your stuff. That way the only programmatic stuff you need to do is register the datasource...

                Hmm maybe even better, let the client register their application context with your Factory and use that as a parent context...
                If I perform the following:
                applicationContext = ClassPathXMLApplicationContext("myContext.xml");
                the application context will be configured and complain about a missing dataSource. How can I register the dataSource with the application context before it is initialized?

                Edit: Your last suggestion worked fine. I made my factory ApplicationContextAware and created the application context with the client application context as parent.
                Last edited by DJViking; Feb 11th, 2008, 06:35 AM.

                Comment

                Working...
                X