Programatically Registering Spring Components with Spring Framework

I have a Spring Boot application that acts as an agent to collect metrics from other Spring Boot applications (clients). I created a traditional JAR of the agent (Non-fat JAR) and added it to the pom.xml of client. However, I have to modify client code to include @ComponentScan to detect Spring Beans of my agent.

How can I register the components of the agent with Spring, without any modification to client code?

1 answer

  • answered 2018-11-08 07:33 Mallikarjuna Budur

    annotate a method with @Bean to return the class you're referring to load your custom class as a bean in Springboot Application java file.