Announcement Announcement Module
Collapse
No announcement yet.
Disabling Proxy objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disabling Proxy objects

    Hi all.

    A quick question: Is is possible to disable proxying altogether at a global level for objects requested from the spring container?

    I'm using Spring to inject test data[read Value Objects] in my test cases and at a loss to understand as to why the objects retrieved are not normal instances but instances enhanced using CGLIB. Is this default behavior? Currently the workaround I'm using to prevent a ClassCastException is something along these lines:

    Code:
    <beans>
     <bean class="pkg.class">
      <property name="var1" value="val1" />
      <aop:scoped-proxy proxy-target-class="true" />
     </bean>
     <!-- more beans -->
    </beans>
    Any suggestions would be appreciated.

    ./sasuke

  • #2
    I'm afraid the problem is unclear.

    You just said that you inject objects to particular beans and cglib-proxies are returned instead of them from the spring context. Well, if you don't want proxies just disable aspect configuration at the spring config.

    Am I missing something here?

    Comment


    • #3
      Originally posted by denis.zhdanov View Post
      I'm afraid the problem is unclear.

      You just said that you inject objects to particular beans and cglib-proxies are returned instead of them from the spring context. Well, if you don't want proxies just disable aspect configuration at the spring config.

      Am I missing something here?
      Thanks for the reply Denis.

      You are correct; I need to disable proxies but not at a global level. The scenario is:
      • Our application is created using Spring hence we have a Spring config file [application.xml] at the application level which deals with the business logic beans. This file requires AOP features
      • The test suite which uses the application classes has a separate Spring config file [test-data.xml] which contains only value objects and hence doesn't require any AOP features.
      • In my test case class, I create a Spring ApplicationContext by passing in both the config files so that I can retrieve both business objects and value objects and test them.

      The question is: How do you "disable aspect configuration at the spring config"? Is there any special tag which declared at the top of the config file disables AOP features? Do I have to create separate ApplicationContexts for this case? I have searched the Spring AOP documentation but couldn't find anything related to disabling the proxying.

      Apologies if my explanation of the problem sounds confusing; any ideas appreciated.

      ./sasuke

      Comment


      • #4
        Ok, the problem is clear now

        As far as I understand you create an application context at the test scenario y passing all necessary xml file names to the context constructor. However, you can do the following instead - create separate context objects for the base application xml files and use it as a parent context during construction of another context that is initialized with test xml files. I.e. you can use the following constructor during context initialization - ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) .

        The trick is that spring aop is built on BeanPostProcessor's and BeanPostProcessor's are scoped per-container, so, aop stuff defined at the parent context doesn't influence child test context.

        Comment


        • #5
          Originally posted by denis.zhdanov View Post
          Ok, the problem is clear now

          As far as I understand you create an application context at the test scenario y passing all necessary xml file names to the context constructor. However, you can do the following instead - create separate context objects for the base application xml files and use it as a parent context during construction of another context that is initialized with test xml files. I.e. you can use the following constructor during context initialization - ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) .

          The trick is that spring aop is built on BeanPostProcessor's and BeanPostProcessor's are scoped per-container, so, aop stuff defined at the parent context doesn't influence child test context.
          Ah, this is worth trying out. I'll get back with results as soon as get the opportunity to try this out.

          Thanks for your answer, much appreciated. :-)

          ./sasuke

          Comment

          Working...
          X