SpringBoot搭建多模块工程踩坑
- 所有模块的包名最好相同
- 在controller层的主类上的
@SpringBootApplication
加上scanBasePackages
属性,如果不加IOC会注入不了属性
@SpringBootApplication(scanBasePackages = "org.example")
public class BootControllerApplication {
public static void main(String[] args) {
SpringApplication.run(BootControllerApplication.class, args);
}
}
- 每个POM文件指定JDK版本
<properties>
<java.version>1.8</java.version>
</properties>
- root工程的POM文件只放依赖,springboot打包的plugin放在springboot的模块中
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>top.huanyv.WebApplication</mainClass>
<excludeGroupIds>org.projectlombok</excludeGroupIds>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>