Skip to content

MarceloLeite2604/cor-bean-processor-spring-boot-autoconfiguration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chain Of Responsibility (COR) Bean Processor Spring Boot Starter

TL;DR: You focus on the logic while we handle the chain!

A screen capture presenting a sample code diff with the same project with and without COR Bean Processor library.

What is this about?

COR Bean Processor is a library to assist creating Chain Of Responsibility design patterns on Spring Boot projects. It automatically chain all links together, reducing the amount of non-business code required in the project.

How to use it?

  1. Be sure to add Spring Boot to your project.

  2. Add COR Bean Processor Spring Boot Starter on your project.

    1. For Maven projects add the following on your pom.xml file under <dependencies> tag.
    <dependency>
      <groupId>com.figtreelake</groupId>
      <artifactId>cor-bean-processor-spring-boot-starter</artifactId>
      <version>1.0</version>
    </dependency>
    1. For Gradle projects add the following on your build.gradle file under dependencies declaration.
    implementation 'com.figtreelake:cor-bean-processor-spring-boot-starter:1.0'
    1. You can check the latest version available on Maven Central repository.
  3. Make your Chain Of Responsibility link classes implement ChainLink interface.

  4. Add a ChainLink interface field on the class where ou need your chain and annotate it with either @Autowired or @Inject (if you are using Javax Inject)

  5. That is it! COR Bean Processor will automatically create the chain and Spring Boot will inject its first list into the target class.

If you need further details about implementation, feel free to check the examples repository.

FAQ

Q: Does COR Bean Processor handles multiple chains?

A: Yes! As long as each ChainLink implementation declares a different type on its template, the library will concatenate each link group separately. For more details about it check multiple chains project inside the example repository.


Q: What if my links must be concatenated in a specific order?

A: You can annotate your links with @Order. The library will respect the specification and chain links in the defined order. For more details check ordered links inside the example repository.


Q: I need one link to be the first of my chain. Do I need to add @Order annotation on all my links?

A: No. Just add @Primary annotation on your first link and the library will use it as the first chain element. For more details check chain with primary link example.

How can I contribute?

Try out the library. If you like the outcome, give a star for its repository, share or talk about it with your IT friends and colleagues. This is a work I have been doing in my spare time and I really would like to see that people appreciate the time I have invested on it.

If you liked the project and really want to demonstrate your appreciation, you can send me a "thank you" coffee. 🙂

Yellow PayPal Donation button with "donate" text written on it

Sources

This library was implemented after reading Spring Boot - Auto Configuration and Spring Boot Features - Developing Auto Configuration documentation sections.

Also, thanks to Stéphane Nicoll and his spring-boot-master-auto-configuration repository which helped me understand the minor details necessary to create a Spring starter library.