Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to disable cglib proxy dependency from spring 3.x

  1. #1
    Join Date
    Feb 2011
    Posts
    8

    Default How to disable cglib proxy dependency from spring 3.x

    Hi,
    We are using spring 3.x along with hibernate 3.x and facing very critical memory leak issue from cglib and because of which classes are not getting cleared up from memory after redeploy. I tried all possible options to remove cglib dependency from hibenrate and finally upgraded to hibernate 3.3.2 which uses javassist as proxy lib. But, how to eliminate the dependency of cglib from spring.

    Where ever there is interface driven classes are there, I think spring will use Java JDK proxies, but for direct classes it uses cglib.
    We are using org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean to integrate with hibernate. I think it's not driven through interface and because of it's using cglib. How can I solve the problem.
    public class DAOHibernate<T, ID extends Serializable> implements
    IGenericDAO<T, ID> {

    @Autowired
    private SessionFactory sessionFactory;

    }


    Please suggest on how to solve the problem.

    Thanks
    Santhosh

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

    Default

    Not sure what you are using as dependency management but simply remove cglib from the classpath. Try to figure out what is using cglib, make sure you aren't forcing class proxies anywhere or use @Controller without interfaces....
    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
    Feb 2011
    Posts
    8

    Default

    Is it that if atleast one class is using @controler i.e. class proxy then all the objects will be instantiated using class proxy?
    For example, if I have 3 classes which are interface driven and 2 are direct classes. So, what will be the spring behavior? Will it load all 5 instances using class proxies? or only 2 (which are direct classes) using class proxies?

    Thanks
    Santhosh

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

    Default

    By default spring does auto detection... If it is an interface spring will use jdk dynamic proxies else it will use cglib.
    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
    Feb 2011
    Posts
    8

    Default

    Marten,
    Thanks for the response. Just to narrow down my question, is auto scanning happens for each instance separately? Out of 4 registered beans with spring, 2 are having interfaces and other 2 are direct classes. So all the 4 will use CGLIB proxy? or 2 JDK and 2 CGLIB?

    Also, I have below sessionfactory bean in the XML file, for which it is using CGLIB proxy to load it.

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">

    This sessionFactory bean I am associating in DAOHibernate class using Autowired with interface as below
    @Autowired
    private SessionFactory sessionFactory;

    In this is it is using CGLIB to load the sessionfactory. Not sure why? Can you or someone help on this behavior?

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

    Default

    There is no reason why the AnnotationSessionFactoryBean requires cglib to load (in fact I have multiple project with this FactoryBean and WITHOUT cglib). So not sure how you come to the conclusion it uses glib to load (unless you are using spring 2.0 and hibernate < 3.0.1)...

    Auto-detection is going to happen for your beans so depending on your aspects/advices it will either create a jdk or cglib proxy. But the fact that you use component scanning doesn't automatically mean there is a proxy created! Proxy will only get created if you use aop or scoped 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

  7. #7
    Join Date
    Feb 2011
    Posts
    8

    Default

    We are not using AOP but using request scoped bean. We are integrating jersey with spring using request scoped bean. Hopefully this is trying to create proxies.

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

    Default

    If you use scoped beans and it doesn't implement an interface a class proxy will be created. Do you also use spring transaction management, if so you are using AOP (maybe not knowingly but tx is implemented with aop).
    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

  9. #9
    Join Date
    Feb 2011
    Posts
    8

    Default

    Marten,
    Thanks alot for clarifying my doubts. Yes we are using spring transaction management using @Transactional. Can you please clarify the behavior of proxy. Is it going to individually check for each bean whether to create JDK proxy/CGLIB proxy based on whether it implements interface or not.

    In our example, Out most bean which is integrated with jersey uses @PATH and other annotations, but it will not implement interface. But, all inner referenced beans implements interfaces. In this case I guess only outer class will be created using CGLIB proxy and all inner beans should be by JDK proxy. Is my assumption correct?

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

    Default

    If you don't force class proxies it basically checks bean for bean. However it will only create a proxy if needed!! So it isn't creating proxies by default for ALL beans it will only create proxies if it is a scoped proxy or adviced (aop) bean.
    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

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
  •