How to do multi-project public configuration in springboot

I have multiple spring boot projects, and I want to extract the common code and configuration of these projects into a common configuration. For example,

@EnableAspectJAutoProxy
public class DefaultConfig {}

I want all projects to open AOP, but I don"t want every project to copy such a code. What should I do to make multiple projects share a single code?

Mar.22,2021

you first write a DefaultConfig class, and then you have @ Import (xxpackage.DefaultConfig) in each project.


I found a more elegant solution: customize a spring-boot-start

@EnableAspectJAutoProxy
@Configuration
public class DefaultConfig {}

then add

to spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=xxxx.xxx.DefaultConfig

finally, you can package and publish it in maven.

each project only needs to add this maven dependency without intruding into any Java code.

Menu