javaspringspring-bootspring-restcontrollerspring-context

Spring-Boot Components from other jar are not in context


I have following situation. JDK 17, Spring-Boot: 2.6.2. A gradle multi-project. One project is a library (java-library, no spring boot plugin). Another project is a spring boot application with spring boot plugin. Generally, the spring dependency management plugin is not used, gradle platform concept is used instead. Application project includes dependency to library project per "implementation(project(':.."

Library:

like: library root package is a.b.c and application root package is a.b.d

    @Configuration
    @ComponentScan(basePackageClass = LibraryConfig.class)
    public class LibraryConfig {

Application:

  @Configuration
  @Import(a.b.c.LibraryConfig.class)
  public class AppConfig {

Problem: Classes from the library are there in runtime - we are able to load them. No any component of the library is in context (not registered), neither services nor rest controllers.

What are we missing?

We have tried different constellations of imports and scans. Also added component scan to application class and set there particular packages. Nothing helped.


Solution

  • The problem was, that the main application was using spring boot indexing annotation processor and library - not. So after enabling the annotation processor for library problem was solved.