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:

401 questions
192
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,355
  • 4
  • 17
  • 22
141
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
  • 2,119
  • 3
  • 17
  • 20
63
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
  • 16,863
  • 27
  • 87
  • 114
42
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…
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,638
  • 8
  • 47
  • 84
37
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
  • 15,954
  • 56
  • 188
  • 315
27
votes
2 answers

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
  • 47,675
  • 117
  • 331
  • 600
26
votes
1 answer

What does $$ and mean in Java stacktrace?

I often 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,745
  • 6
  • 34
  • 68
20
votes
1 answer

java.lang.ExceptionInInitializerError with Java-16 | j.l.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module

I have cglib as a transitive dependency in a Maven project. Despite adding what I believe to be the correct --add-opens I can't get the library to work with Java 16. How do I get cglib to work with Java 16? I raised this issue on the github…
Robert Bain
  • 9,113
  • 8
  • 44
  • 63
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,362
  • 2
  • 27
  • 60
18
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
  • 883
  • 10
  • 22
18
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
  • 311
  • 2
  • 7
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
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
  • 47,929
  • 21
  • 130
  • 148
16
votes
1 answer

Spring AOP CGLIB proxy's field is null

Description Using the vlcj component, the custom component appears as a result of the AOP proxy object null. MediaList Class public class MediaList { private libvlc_media_list_t mediaListInstance; public MediaList(LibVlc libvlc,…
forDream
  • 386
  • 1
  • 6
  • 17
1
2 3
26 27