BAEL-633 craete cglib template

This commit is contained in:
Tomasz Lelek 2017-02-14 16:17:55 +01:00
parent 491d36e745
commit b3303dc0cf
4 changed files with 75 additions and 0 deletions

47
cglib/pom.xml Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cglib</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<cglib.version>3.2.4</cglib.version>
<junit.version>4.12</junit.version>
</properties>
</project>

View File

@ -0,0 +1,7 @@
package com.baeldung.cglib.proxy;
public class SampleClass {
public String test(String input) {
return "Hello world!";
}
}

View File

@ -0,0 +1,20 @@
package com.baeldung.cglib.proxy;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.FixedValue;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SampleClassTest {
@Test
public void testFixedValue() throws Exception {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(SampleClass.class);
enhancer.setCallback((FixedValue) () -> "Hello cglib!");
SampleClass proxy = (SampleClass) enhancer.create();
assertEquals("Hello cglib!", proxy.test(null));
}
}

View File

@ -191,6 +191,7 @@
<module>xstream</module>
<module>struts2</module>
<module>cglib</module>
</modules>