I have created an external library for my Spring Boot projects, let’s call it korimlib. It contains a reusable service.

package com.korimsoft.korimlib;

@Autowired
public class MyReusableService {

}

I have imported the korimlib into the Korimapp - one of the korimlib's consumers.'

Korimapp’s pom.xml
<dependency>
        <groupId>com.korimsoft</groupId>
        <artifactId>korimlib</artifactId>
        <version>1.0-SNAPSHOT</version>
</dependency>

One would expect that a simple import in a client class would do. Well, Spring Boot is not that clever.

This won’t do
package com.korimsoft.korimapp;

import com.korimsoft.korimlib.MyReusableService;

@Service
public class Client {

    @Autowired
    private MyReusableService service;
}

If I try tu run this simple example, I get an UnsatisfiedDependencyException. The DI container is not able to locate MyReusableService. There is one more thing to do: Configure the DI container to look also in the external library for dependencies.

Client application configuration
@Configuration
@ComponentScan({"com.korimsoft.korimlib", "com.korimsoft.korimapp"})
public class Config {

}

Voila!