Spring interface bean

Make bean definers from interfaces

License

License

GroupId

GroupId

org.decembrist.spring
ArtifactId

ArtifactId

spring-interface-bean
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Spring interface bean
Make bean definers from interfaces
Project URL

Project URL

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

Source Code Management

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

Download spring-interface-bean

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 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

Versions

Version
1.1.0
1.0.0