Spring interface bean

Make spring proxies in easy way

Лицензия

Лицензия

Группа

Группа

org.decembrist.spring
Идентификатор

Идентификатор

spring-easy-proxy
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

Spring interface bean
Make spring proxies in easy way
Ссылка на сайт

Ссылка на сайт

https://github.com/decembrist-revolt/spring-easy-proxy
Система контроля версий

Система контроля версий

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

Скачать spring-easy-proxy

Зависимости

runtime (4)

Идентификатор библиотеки Тип Версия
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

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
1.0.0