0

We are building a Spring-based Java library that has several @Autowired assignments, which pick up @Bean instances from the library path, detected at runtime.

That works great when we test the application directly (with an @SpringBootApplication in the library)

However when we include the library as a dependency in other projects, it does not do the component scan of the library classes, and so the @Autowired injections never happen.

Of course we could tell the application developers to add the library path to their component scan, but that would lead to questions, errors, and frustration.

How can we tell Spring to do a component scan of the library classes, without explicitly including the scan base in the consumer applications?

Vinny Gray
  • 477
  • 5
  • 18

1 Answers1

0

You could create a configuration in your library which defines the components the library needs. This answer shows something like that.

Another way would be to create your own autoconfiguration. This article in the spring documentation describes how it is working.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mehtrick
  • 518
  • 3
  • 12