SpringBoot 多模块 开发笔记

32 阅读1分钟
  • 多模块 项目 打包
  • 点击 idea 左侧的 Maven 选择 生命周期
  • 点击 package 命令

尝试打包 出现 Unable to find main class

  1. 删除 主模块中的 打包插件
  2. 将打包插件 添加到 web 模块中
  • 以下是 web 模块中的 pom.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.codervibe</groupId>
        <artifactId>springbootmultimodule</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>com.codervibe</groupId>
    <artifactId>web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>web</name>
    <description>web</description>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.codervibe</groupId>
            <artifactId>server</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.codervibe</groupId>
            <artifactId>model</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>
    <build>
        <finalName>springbootmultimodule</finalName>
        <plugins>
            <!--可执行的JAR/WAR -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

再次尝试打包

  • 出现 ....Error creating bean with name 'userController' ...
  • 报错信息太多 这里不在粘贴展示
  • 所有东西都找不到了
    1. 添加 applicationContext.xml 解决
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- 配置包 扫描路径 -->
    <context:component-scan base-package="com.codervibe"/>
    <context:component-scan base-package="com.codervibe.model"/>
    <!-- 配置Mapper扫描器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.codervibe.mapper"/>
    </bean>

</beans>