Unable to use spring boot application as a dependency to another spring boot application

Viewed 169

Unable to use spring boot application as a dependency to another spring boot application. Can anyone please point me to the correct source? I want to implement a central logging application using AspectJ (which is again spring boot application ) which will listen to different spring boot applications(maybe 6 other applications) method executions, and it will persist the data into DB.

I was using the below config in pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>repackage</id>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

And add this as dependency on other spring boot application POM.XML file but still getting No qualifying bean of type 'com.client.client.NewClass' available*

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.client.client.NewClass;


@SpringBootApplication
public class DemoApplication implements CommandLineRunner{
    
    @Autowired
    private NewClass newClass;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println(newClass.getValue());`enter code here`
        
    }

}
1 Answers

IMO you have two choices:

A) Write the AspectJ code in a common module (not a full spring boot app). You can make it optional dependency(research about optional dependency in maven if you don't know already) if you like.

Then use that common module as library in other apps. If you want to write the logs to database, configure the log database as secondary database(again google on how to create two datasources in spring).

You will just need to update the properties file and pom.xml if you want to use this option.

B) Write a full spring boot app with REST endpoints to receive messages containing the info to log. Update each of your app to call the REST api with the info to log.

Related