Spring interface bean

Make spring proxies in easy way

License

License

GroupId

GroupId

org.decembrist.spring
ArtifactId

ArtifactId

spring-easy-proxy
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Spring interface bean
Make spring proxies in easy way
Project URL

Project URL

https://github.com/decembrist-revolt/spring-easy-proxy
Source Code Management

Source Code Management

https://github.com/decembrist-revolt/spring-easy-proxy

Download spring-easy-proxy

Dependencies

runtime (4)

Group / Artifact Type Version
org.springframework.boot : spring-boot-autoconfigure jar 2.4.5
org.springframework : spring-core jar 5.3.6
org.springframework : spring-beans jar 5.3.6
org.springframework : spring-context jar 5.3.6

Project Modules

There are no modules declared in this project.

Spring Easy Proxy
Library gives an ability to make spring interface proxy beans in easy way (Like spring data repositories do)

Java CI

Getting started
Maven:

<dependency>
    <groupId>org.decembrist.spring</groupId>
    <artifactId>spring-easy-proxy</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle:

implementation "org.decembrist.spring:spring-easy-proxy:1.0.0"

Example:
@EasyProxy

//1. Define interceptor bean (any org.aopalliance.aop.Advice class)
@Component
public class Interceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        // do some staff
        return invocation.proceed();
    }
}

//2. Use @EasyProxy annotation to create singleton proxy bean
@EasyProxy({Interceptor.class}) //Interceptor array here
public interface ProxyInterface {
    String proxyMethod(String param);
}

@Component
class AnotherClass {
    //3. ProxyInterface above will be injected with Interceptor.class handler
    @Autowired private ProxyInterface proxy;
}

@EasyProxyInterface

//1. Define interceptor bean (any org.aopalliance.aop.Advice class)
@Component
public class Interceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        // do some staff
        return invocation.proceed();
    }
}

//2. Use @EasyProxyInterface annotation to create proxy marker
@EasyProxyInterface({Interceptor.class}) //Interceptor array here
public interface ProxyInterfaceMarker {
    String proxyMethod(String param);
}

//3. Extend marker interface to create singleton proxy bean
public interface MarkedProxyInterface extends ProxyInterfaceMarker {
    String proxyMethod(String param);
}

@Component
class AnotherClass {
    //4. MarkedProxyInterface above will be injected with Interceptor.class handler
    @Autowired private MarkedProxyInterface proxy;
}

Interceptor injection:

@Component
public class TestInterceptor1 implements MethodInterceptor, ApplicationContextAware {

    private ApplicationContext applicationContext;

    //The only way to use another beans from interceptor for now
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

Checked:

  1. Works for kotlin
  2. @EasyProxyInterface interfaces work as .jar spring boot library component
  3. Tested with graalvm-ce-java11-21.0.0.2
  4. Tested with java 8

Properties:

#disable easy proxies
spring.easy-proxy=false

Versions

Version
1.0.0