Questions tagged [cglib]

CGLib (Code Generation Library) is a run time code generation library for the Java platform licensed under the Apache 2.0 license.

CGLib (Code Generation Library) is mainly used the generation of class proxies. This is achieved by creating subclasses at run time where method invocations are intercepted by user defined methods. Additionally, cglib offers different extension such as for example bean utilities. cglib is built on top of ASM.

Alternative code generation libraries for the JVM that are still under active development are:

365 questions
168
votes
4 answers

What is the difference between JDK dynamic proxy and CGLib?

In case of the Proxy Design Pattern, What is the difference between JDK's Dynamic Proxy and third party dynamic code generation API s such as CGLib? What is the difference between using both the approaches and when should one prefer one over…
KDjava
  • 2,123
  • 4
  • 15
  • 20
110
votes
1 answer

Calling a @Bean annotated method in Spring java configuration

I'm curious about how spring injection handles calling methods with the @Bean annotation. If I put a @Bean annotation on a method, and return an instance, I understand that that tells spring to create a bean by calling the method and getting the…
markwatson
  • 1,799
  • 2
  • 15
  • 19
61
votes
5 answers

Are there alternatives to cglib?

Just out of curiosity, are there any (stable) open source projects for runtime java code generation other than cglib? And why should I use them?
Mauli
  • 15,951
  • 26
  • 80
  • 112
38
votes
1 answer

how to retransform a class at runtime

I am tring modify class which already loaded in a jvm. The solution which I found is: 1st Attach an agent to a jvm specified by pid. (e.g. 8191)(Codes: AttachTest) 2nd Find the class which you want modified from those that have already been loaded…
Nick Dong
  • 3,111
  • 6
  • 39
  • 68
36
votes
3 answers

Dynamic Java Bytecode Manipulation Framework Comparison

There are some frameworks out there for dynamic bytecode generation, manipulation and weaving (BCEL, CGLIB, javassist, ASM, MPS). I want to learn about them, but since I don't have much time to know all the details about all of them, I would like to…
29
votes
1 answer

What is CGLIB in Spring Framework?

What is CGLIB and how it is related to Spring? Do we have to define usage of CGLIB explicitly when using Spring Framework?
Punter Vicky
  • 12,516
  • 39
  • 134
  • 241
22
votes
1 answer

What does $$ and means in java stacktrace?

Many times I get stacktraces like this one (please see the arrow for the confusing line): org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is…
user1028741
  • 2,376
  • 4
  • 25
  • 51
19
votes
5 answers

VerifyError using Mockito 1.9.5 and DexMaker-Mockito-1.0

Like many others I was excited to hear that Mockito now works with Android and followed this tutorial to see it with my own eyes. Everything seemed fan-flapping-tastic and I got underway incorporating the mocking solution into my Android Test…
BrantApps
  • 6,074
  • 2
  • 23
  • 57
18
votes
4 answers

Retain annotations on CGLIB proxies?

Am trying to create an object using an AOP framework which uses CGLIB to create proxy objects. Strangely enough, the "enhanced" proxy object is devoid of ANY annotations the previous class had! Can anyone tell me how can I make CGLIB retain the…
Nirav
  • 211
  • 2
  • 3
17
votes
1 answer

Mocking a property of a CGLIB proxied service not working

I'm having an issue when trying to mock a property of a service from within a Junit test: @ContextConfiguration("classpath:application-config.xml") @RunWith(SpringJUnit4ClassRunner.class) public class FooServiceTests { @Autowired private…
franDayz
  • 762
  • 7
  • 20
17
votes
2 answers

Mixing JDK and CGLIB proxies within Spring

I have an application running with Spring, and I'm using AOP in some places. Since I want to use the @Transactional annotation at interface level, I have to allow Spring to create JDK proxies. So, I don't set the proxy-target-class property to true.…
Thiago Coraini
  • 301
  • 2
  • 7
14
votes
3 answers

Java detect if class is a proxy

Is it possible to detect if a class is a proxy (dynamic, cglib or otherwise)? Let classes Aand B implement a common interface I. Then I need to define a routine classEquals of signature public boolean classEquals(Class a, Class
Johan Sjöberg
  • 43,692
  • 19
  • 120
  • 139
14
votes
5 answers

Slow to start after upgraded to Spring 3

I use Struts2 and my application has thousands of action classes managed by Spring. I used Spring 2.5.6 before and my application starts quickly. But when I changed Spring to 3.0. I got a extremely slow start up of Tomcat. For each action class, I…
Matt
  • 1,540
  • 5
  • 20
  • 34
13
votes
3 answers

How can I create a dynamic proxy in java that retains parameter annotations on methods?

I currently am trying to proxy some existing JAX/RS resources, in order to allow me to use the Hibernate Validator's method validation support. However, when I proxy my class (currently using cglib 2.2), the FormParam annotation is not present on…
Peter Hart
  • 4,745
  • 2
  • 20
  • 28
13
votes
1 answer

How to know original class name if wrapped into proxy by Spring?

I am trying to obtain some classes name by getClass().getSimpleName() under Spring and it returns something like MyClass$$EnhancerBySpringCGLIB$$SOMEHEX This is probably because Spring wraps the class into proxy. Is there any portable way to…
Dims
  • 37,353
  • 77
  • 251
  • 478
1
2 3
24 25