0

is it possible to implement an interface using Annotaitons/Spring AOP/Proxies? For example, I have the simplified interface Foo. The first and second method usually only return a value. These values could be annotated on class level like shown in class Bar. The third method will be dynamically implemented by class Bar and annotated with the @CallMethod annotation.

At the end Spring beans of class Bar should implement the interface Foo.

public interface Foo {
    public URI getID();
    public String getRequires();
    public void call(Item item);
}

@FooAnnotation(id = "myID", requires = "text/plain")
public class Bar {
    @CallMethod
    public void myCallMethod(Item item)
}
Kai Schlegel
  • 183
  • 2
  • 11
  • 1
    Have you looked at [introductions](http://docs.spring.io/spring/docs/4.0.4.RELEASE/spring-framework-reference/htmlsingle/#aop-introductions)? – Andrei Stefan Aug 19 '14 at 09:00
  • There is nothing out of the box that I know of, but you could probably implement something like this on your own using `CGLIB` and reflection – geoand Aug 19 '14 at 10:01
  • I can't see how you could do this, or not without a great deal of work anyway. During compilation, other classes would need to know the Bar implements Foo so you'd need to modify the bytecode for Bar at compile time, rather than run time. This basically means writing a pre-processor for the bytecode or source code. You could look at MPS, the DSL in IntelliJ, as that has an implementation of Java as a base language which you could then extend. – matt helliwell Aug 19 '14 at 10:52

0 Answers0