-
Jul 23rd, 2011, 05:04 AM
#1
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
-
Jul 24th, 2011, 04:26 AM
#2
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....
-
Jul 24th, 2011, 10:59 PM
#3
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
-
Jul 25th, 2011, 02:15 AM
#4
By default spring does auto detection... If it is an interface spring will use jdk dynamic proxies else it will use cglib.
-
Jul 26th, 2011, 12:53 AM
#5
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?
-
Jul 26th, 2011, 05:34 AM
#6
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.
-
Jul 26th, 2011, 10:47 AM
#7
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.
-
Jul 26th, 2011, 12:17 PM
#8
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).
-
Jul 26th, 2011, 09:27 PM
#9
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?
-
Jul 27th, 2011, 03:21 AM
#10
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.
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
-
Forum Rules