0


【spring】-多模块构建二-问题整理

1、bean注入问题

The injection point has the following annotations:

  • @org.springframework.beans.factory.annotation.Autowired(required=true)

解决1:

由于引入的bean类 不属于启动类的子模块下,需要在启动类手动声明扫描的类

也适用于公共子模块的bean引入问题

/**指定要扫描的Mapper类的包的路径*/
@MapperScan({"com.bhl.**"})
@SpringBootApplication
public class UserApplication {

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

}

或者使用

@ComponentScan("com.bhl")

解决2:

调整目录结构,位于子目录下

2、服务启动问题

1、Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean

缺少依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2、Unable to start embedded Tomcat

缺少tomcat容器

<!-- servlet包 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
</dependency>

3、没有主清单属性

提示错误:Unable to find main class

在父pom中移除 spring-boot-maven-plugin

<!-- <build>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <configuration>
                 <excludes>
                     <exclude>
                         <groupId>org.projectlombok</groupId>
                         <artifactId>lombok</artifactId>
                     </exclude>
                 </excludes>
             </configuration>
         </plugin>
     </plugins>
 </build>-->

在存在SpringBootApplication启动类的模块中,添加

必须要指定版本

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.5.13</version>
</plugin>

本文转载自: https://blog.csdn.net/xcg340123/article/details/136663650
版权归原作者 宣晨光 所有, 如有侵权,请联系我们删除。

“【spring】-多模块构建二-问题整理”的评论:

还没有评论