Created
July 13, 2016 13:48
-
-
Save ogregoire/bf8bcbe22fd6427bff9acdbdaf1c119e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Not empty content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package framework; | |
import javassist.util.proxy.*; | |
public class Framework { | |
public MethodHandler getMethodHandler() { | |
return (self, overridden, proceed, args) -> { | |
System.out.println("Proxied!"); | |
return proceed.invoke(self, args); | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package framework; | |
import java.lang.annotation.*; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.METHOD) | |
public @interface FrameworkAnnotation { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package guiceproxy; | |
import com.google.inject.AbstractModule; | |
import com.google.inject.Inject; | |
import com.google.inject.matcher.Matchers; | |
import framework.Framework; | |
import framework.FrameworkAnnotation; | |
import org.aopalliance.intercept.MethodInterceptor; | |
/** | |
* | |
* @author Olivier Grégoire | |
*/ | |
public class MyModule extends AbstractModule { | |
@Override | |
protected void configure() { | |
FrameworkInterceptor interceptor = new FrameworkInterceptor(); | |
bindInterceptor(Matchers.any(), Matchers.annotatedWith(FrameworkAnnotation.class), interceptor); | |
requestInjection(interceptor); | |
} | |
static class FrameworkInterceptor implements MethodInterceptor { | |
@Inject | |
Framework framework; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>blah</groupId> | |
<artifactId>guice-proxy</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<maven.compiler.source>1.8</maven.compiler.source> | |
<maven.compiler.target>1.8</maven.compiler.target> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>com.google.inject</groupId> | |
<artifactId>guice</artifactId> | |
<version>4.1.0</version> | |
</dependency> | |
<dependency> | |
<groupId>org.javassist</groupId> | |
<artifactId>javassist</artifactId> | |
<version>3.20.0-GA</version> | |
</dependency> | |
<dependency> | |
<groupId>org.objenesis</groupId> | |
<artifactId>objenesis</artifactId> | |
<version>2.4</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment