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
0
votes
1 answer

Interception of package-private method for JDK class with CGLib

I'm trying to create CGLib Proxy for java.net.SocketImpl class using code like: Enhancer e = new Enhancer(); e.setSuperclass(SocketImpl.class); e.setCallback(new MethodInterceptor() { @Override public Object intercept(Object…
Dmitry Spikhalskiy
  • 5,379
  • 1
  • 26
  • 40
0
votes
1 answer

Class generation and enhancement with CGLIB

The code is in Scala, but hopefully understandable for Java programmers as well. I have the following class: class SampleClass { def test(in: String) = "Hello world!" } I have the following code that creates an enhanced instance of this…
Anatoliy Kmetyuk
  • 708
  • 1
  • 6
  • 10
0
votes
2 answers

Spring Proxy doesn't call my method

I'm trying AOP for the first time and for that I've developed a small and easy example for that but I'm finding some problems. Firstly, Spring asks me for adding a dependency to cglib library by printing the following error: cannot proxy target…
Fernando
  • 751
  • 2
  • 13
  • 27
0
votes
1 answer

Java RMI export subclass : class cast exception

I have an application that detects some classes as being RMI exportable, and exports them. The exportable classes should implement an interface, that will be present on the RMI client to do the cast and make the stub usable. I then execute the…
dlsa
  • 3,402
  • 2
  • 17
  • 17
0
votes
0 answers

After spring upgrade: could not generate CGLIB subclass of class class com.sun.proxy.$Proxy

My application was recently upgraded from Spring 3.x to Spring 4.x (via moving our app to Spring-boot, latest version) We have some AOP in place that look like this and worked fine prior to this upgrade: (cglib was being used to create the…
bitsofinfo
  • 994
  • 3
  • 16
  • 34
0
votes
2 answers

How to modify/decorator an object returned from 3rd party API using javassist/CGLib

I have an 3rd party API call which returns the following object: public class A { protected void common() { System.out.println("common is called in A"); } public void test1() { common(); System.out.println("test1 is called in…
user1040933
  • 277
  • 5
  • 14
0
votes
2 answers

JavaClassLoader: Why an "NoSuchMethodEx" is thrown here?

I have a problem with the "JavaClassLoader" library. I want to program a launcher for a application. At the end it should be possible to shutdown the program, to update and to start again. Now, I always get an NoSuchMethodEx when I try to invoke…
0
votes
0 answers

howto use CGLIB proxy in spring on GAE?

I'm trying to configure my app to use CGLIB proxy on GAE according to docs http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html I've set in my applicationContext.xml the attribute proxy-target-class attribute of the …
mkk
  • 3
  • 3
0
votes
1 answer

How to copy a private attribute when using CGLIB?

I have the following example where I try to copy a private attribute from the source instance to the target instance. public class MyClass { public void cloneTo(MyClass target) { target.identifier = this.identifier; // identifier is not null …
Renato Dinhani
  • 35,057
  • 55
  • 139
  • 199
0
votes
1 answer

Using cglib to implement annotations

I'm new to cglib, but it seems like the right tool for the job, so here goes: Suppose I have an annotation classes Foo and Bar, and an enum class B, such that Foo and Bar are declared as follows: public @interface Foo { public B…
Kelvin Chung
  • 1,327
  • 1
  • 11
  • 23
0
votes
1 answer

Create Mixin without using interfaces

In Java, I have some legacy classes (from 3rd party library which I cannot edit) that to not implement any interfaces, but for which I would like to create a mixin. I have looked at cglib for creating mixins, but this tutorial states that cglib…
mchen
  • 9,808
  • 17
  • 72
  • 125
0
votes
1 answer

Dynamically mirroring class and adding constructor

I have a class with default visibility without any explicit constructors. i want to generate similar class (with same methods and annotations) but with explicit public default constructor. is it possible in easy way? any ready to use proxy…
piotrek
  • 13,982
  • 13
  • 79
  • 165
0
votes
1 answer

How can i get the object enhanced by cglib

I'm using spring and cglib and i have those classes: public class A { . . private Souscripteur souscripteur; private List contrat; // getter and setter } public class B { . . private Souscripteur souscripteur; //getter…
Sidaoui Majdi
  • 399
  • 7
  • 26
0
votes
1 answer

NamedParameterJdbcTemplate and CGlib in Spring AOP

Hi All in my Spring application i have used AutoWired NamedParameterJdbcTemplate. @Autowired NamedParameterJdbcTemplate namedParametersJdbcTemplate; in my rest-servlet.xml
Paresh Dudhat
  • 1,166
  • 1
  • 14
  • 28
0
votes
2 answers

CGLIB proxy error after spring bean definition loading into XmlWebApplicationContext at runtime

I load additional singleton beans definitions at runtime from external jar file into existing XmlWebApplicationContext of my application: BeanFactory beanFactory = xmlWebApplicationContext.getBeanFactory(); DefaultListableBeanFactory…
VasylV
  • 1
  • 2