Spring interface bean

Make bean definers from interfaces

Лицензия

Лицензия

Группа

Группа

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

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

spring-interface-bean
Последняя версия

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

1.1.0
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

Spring interface bean
Make bean definers from interfaces
Ссылка на сайт

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

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

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

https://github.com/decembrist-revolt/spring-interface-bean

Скачать spring-interface-bean

Зависимости

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 Interface Bean Definition
Library gives an ability to make beans without stereotype annotations (@Service @Component etc.) but through interface inheritance (Like spring data repositories do)

Getting started
Maven:

<dependency>
    <groupId>org.decembrist.spring</groupId>
    <artifactId>spring-interface-bean</artifactId>
    <version>1.1.0</version>
</dependency>

Gradle:

implementation "org.decembrist.spring:spring-interface-bean:1.1.0"

Tested spring-boot version: 2.4.5
Example:

//1. Extend class with IBean interface to make it singleton bean
class SomeClass implements IBean {}

class AnotherClass {
    //2. SomeClass above will be injected (Singleton scope)
    @Autowired private SomeClass someClass;
}

//3. SubInterface works the same way
interface InterfaceBeanSubInterface extends IBean {
}

class SomeClass2 implements InterfaceBeanSubInterface {}

class AnotherClass2 {
    //4. SomeClass2 above will be injected (Singleton scope)
    @Autowired private SomeClass2 someClass;
}

To use without springboot autoconfiguration:

//import postprocessor
@Import(InterfaceBeanPostProcessor.class)

Manual interface bean functionality:
If you don't want to use another dependency just copy this bean to your codebase InterfaceBeanPostProcessor

//And replace IBean.class whatever interface you want to be bean definer
scanner.addIncludeFilter(new AssignableTypeFilter(IBean.class));

Exceptions:

  1. If your bean class has one of stereotype annotations - everything works as usual, interface bean postprocessor ignores that classes
  2. Only singleton scope supported. Now you can't change interface beans scope, you should use stereotype annotations in this case

Properties:

#disable interface bean definition
spring.interface-bean=false

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

Версия
1.1.0
1.0.0