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
9
votes
2 answers

Abstract DAO pattern and Spring's "Proxy cannot be cast to ..." problem!

I know this is very often asked , but I cannot find a working solution : This is my AbstractDAO : public interface AbstractDao { public T get(Serializable id); //other CRUD operations } And this is my JPA's implementation: public abstract…
smallufo
  • 11,516
  • 20
  • 73
  • 111
8
votes
0 answers

mock-maker-inline makes other mocks not work

I tried out the mock-maker-inline "Incubation" feature of Mockito to be able to mock a final class (problem described and discussed here). Since then other tests fail with: org.mockito.exceptions.misusing.NotAMockException: Argument passed to…
Tchypp
  • 1,075
  • 2
  • 13
  • 20
8
votes
1 answer

spring, how to change cglib naming policy

When spring creates a proxy, it uses cglib with default naming policy. Is there any way to change the naming policy? Generated class names clash with another framework I use.
piotrek
  • 13,982
  • 13
  • 79
  • 165
8
votes
1 answer

Should I upgrade to CGLIB 3.0?

I would like to know if/why I should upgrade CGLib 2.2.2 to Version 3.0. I am using CGLib with the latest versions of Hibernate/Spring/Mockito and Java 7. I can not find release notes or upgrade directions for this version anywhere on the web.
tine2k
  • 1,521
  • 1
  • 16
  • 21
8
votes
2 answers

Spring 3.2 unit testing with Java based configuration

I am using Spring 3.2 with Java based configuration and have some problems with my unit tests (JUnit 4.8.1). So this is a test runner: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes={TestConfig.class}) public class…
ChrLipp
  • 15,526
  • 10
  • 75
  • 107
7
votes
1 answer

How does spring create proxy for a final class?

Maybe I have some outdated knowledge but it is the same as described here https://stackoverflow.com/a/2657465/2674303 But now I noticed that this example works without any exceptions: @Service @EnableScheduling public final class MyService { …
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
7
votes
3 answers

CGLib Mixin Example

Can somebody give me a good example for Java CGLib Mixin class usage? I've been digging around none of them seems simple enough.
MaX
  • 1,334
  • 13
  • 26
7
votes
3 answers

Does there exist a Babel like compiler for Java?

With javascript if we want to make sure that our code runs in all browser versions we can use Babel. Is there something like this for Java, where we could write our code in Java 9, but it will run in a Java 6 runtime? For example can Kotlin target…
Ole
  • 41,793
  • 59
  • 191
  • 359
7
votes
2 answers

cglib throws an IllegalArgumentException when enhancing the java.util.Date class

I am trying to enhance java.util.Date with cglib. It does not work and I am not experienced with cglib, so I am wondering what is going wrong. For example, the below code enhancing an ArrayList works: @Test public void enhance_ArrayList() { …
Raipe
  • 786
  • 1
  • 9
  • 22
7
votes
1 answer

BeanNotOfRequiredTypeException but was actually of type $Proxy

I need help with a problem with Spring and proxy. org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'fooAPIService' must be of type [com.foo.clientapi.service.FooAPIService], but was actually of type…
MaximeF
  • 4,913
  • 4
  • 37
  • 51
7
votes
4 answers

Mocking CGLIB enhanced objects

Is it true that mockito can't mock objects that were already enhanced by CGLIB? public class Article { @Autowired private dbRequestHandler @Autowired private filesystemRequestHandler @Transactional public ArticleDTO…
samach
  • 3,244
  • 10
  • 42
  • 54
7
votes
2 answers

Spring - Weird Error in Bean Creation

Any idea why I am getting this exception? Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService' defined in class path resource [context.xml]: Initialization of bean failed; nested exception is…
peakit
  • 28,597
  • 27
  • 63
  • 80
7
votes
1 answer

avoiding problems with spring cglib proxy

Using cglib proxies in spring causes: a) double invocation of constructor b) not allow to intercept a method invoked from another method but why spring creates a bean and then a proxy? is it possible to dynamically generate class that extends a…
piotrek
  • 13,982
  • 13
  • 79
  • 165
6
votes
1 answer

Exception setting property value with CGLIB

After attaching newly backuped database, I'm getting an exception: Caused by: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of…
user1143343
  • 255
  • 1
  • 5
  • 14
6
votes
3 answers

ASM or CGLIB analog for Dalvik

I'm looking for a CGLIB analog usable for Dalvik bytecode. Is there such library in the Android world? Maybe, there is a way to translate CGLIB result to Davlik bytecode on-the-fly?
uhbif19
  • 3,139
  • 3
  • 26
  • 48
1 2
3
26 27