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
5
votes
3 answers

How to know the line of a bug in a spring generated bean?

I've got a website build with Spring and jpa (by hibernate). I've got a bug and I don't know how to identify the line where the bug appears. I can't debug it on my ide because it's a live version (all runs fine in local). I've got log which…
Jerome Cance
  • 8,103
  • 12
  • 53
  • 106
5
votes
1 answer

@Async via proxy classes is creating an exception in Spring 3.2

I seem to have come up with a problem. I have a class @Component @Scope("prototype") public class MyClass extends BaseClass { .... ... @Async public void doSomething() { .... } .... } and a Spring Config that contains …
Ben
  • 1,086
  • 3
  • 15
  • 30
5
votes
1 answer

How to mix CGLIB and JDK proxies in Spring configuration files?

This thread is related to a problem I am encountering here regarding the needs for access to protected methods of an advised class. I'm using Spring 3.0.6, and have created a Spring profiling aspect that I am applying to a significant number of…
Eric B.
  • 23,425
  • 50
  • 169
  • 316
4
votes
1 answer

Why is Lazy creation of beans leading to classes with different References/hashCodes in SpringBoot?

Why do bean of classes created using @Lazy annotation have different reference compared to the normal Autowired objects of the same class. I am aware that @Lazy provides bean instance when it is required but i thought it would always be the same…
Luv
  • 169
  • 2
  • 13
4
votes
1 answer

cglib - MethodInterceptor & finalize?

I use cglib MethodInterceptor to wrap a service. In each call to the service it's supposed to open data session, pass call to the service and finally close the session. However, I noticed it misbehaves when invoked from Finalizer. I get the…
Konrad Garus
  • 53,145
  • 43
  • 157
  • 230
4
votes
3 answers

Spring - Classcast exception as CGLIB proxy cannot be forced

Here's the scenario that's driving me nuts. I have a class that has a lookup method - createOther() createOther should create an object of type Other. Other implements OtherInterface and in addition has a method doSomething that's marked…
Raghu
  • 1,140
  • 1
  • 14
  • 22
4
votes
2 answers

Spring Kotlin : Bean fields are null at runtime despite being injected during instantiation

I am giving a try to Spring Kotlin support and I want to achieve the following simple DAO pattern inside a Spring Boot application (Using Spring reactive features, generated thanks to the Spring Initializr website) : @Document data class Person(val…
Irios
  • 81
  • 6
4
votes
3 answers

When is CGLIB proxy used by Spring AOP?

I was reading some articles about Spring AOP and encountered this: AOP proxy: the object created by AOP to implement the aspect contracts. In Spring, proxy objects can be JDK dynamic proxies or CGLIB proxies. By default, the proxy objects will…
Pasha
  • 1,768
  • 6
  • 22
  • 43
4
votes
2 answers

Spring annotations conflicts with my design guidelines

Overview Using Spring 3.0.1 (annotation configuration) Current configuration is using CGLib as proxy creator but this is not my preference Transactions are annotation configured without any special settings All configuration is done with…
Bivas
  • 1,484
  • 1
  • 11
  • 17
4
votes
1 answer

Serialize proxy object created by cglib

As title, I use Jersey to return an object as JSON, but the object is created by cglib proxy: @GET @Produces(MediaType.APPLICATION_JSON) @Path("test") public Response test() { Enhancer enhancer = new Enhancer(); …
yelliver
  • 5,648
  • 5
  • 34
  • 65
4
votes
3 answers

Exception trying to change a CGLib proxy field value

I created a CGLib dynamic proxy of a class, but when I try to access any field declared in the original class, I obtain java.lang.NoSuchFieldException. I need to obtain the field in order to change its value. By the way, this is the class the proxy…
csfb
  • 1,105
  • 1
  • 9
  • 19
4
votes
1 answer

@ControllerAdvice with @Autowired dependency not being injected

Anyone knows how to inject a dependency to a @ControllerAdvice? My @ControllerAdvice extends Spring's ResponseEntityExceptionHandler and implements no interfaces. The @ControllerAdvice gets called correctly, but the @Autowired dependency is never…
pakman
  • 1,676
  • 3
  • 23
  • 41
4
votes
1 answer

why Mixing Spring AOP proxy mechanisms (CGLIB and JDKDynmic) for dependent beans does not work

I have two public classes configured as follows in Spring application context: public class LoadErrorData{ private ExceptionData exceptionData; public LoadErrorData() { } // reminder } public class ExceptionData implements Serializable{ …
Shailesh Vaishampayan
  • 1,766
  • 5
  • 24
  • 52
4
votes
2 answers

Spring Batch @StepScope cannot generate CGLIB subclass

EDIT I created a test project that replicates the issue. It can be found at https://github.com/tomverelst/test-batch. First run the maven command exec:java to start a HSQL database. Then you can run the JUnit test MigrationJobConfigurationTest to…
Tom Verelst
  • 15,324
  • 2
  • 30
  • 40
4
votes
2 answers

Advantages of JDK dynamic proxies

What are the advantages of JDK dynamic proxies? Especially in comparison with CGLIB proxies. Despite the fact that JDK proxies don't bring dependency on any third party library, what are the other advantages of JDK proxies? I read on few places…
Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70