SpringBoot引入其他自定义SpringBoot

目录

自定义被引用的SpringBoot

创建普通Springboot项目

1.去除SpringBootApplication
2.去除Test模块
3.去除application.properties
下面是项目结构
《SpringBoot引入其他自定义SpringBoot》

修改pom.xml的build

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

利用maven打包

使用maven打包完毕后会自动进入本地maven仓库
《SpringBoot引入其他自定义SpringBoot》

创建测试的SpringBoot

与创建普通springboot项目相同,项目结构如下
《SpringBoot引入其他自定义SpringBoot》

引入自定义的Springboot依赖

在pom.xml中添加自定义Springboot依赖

自定义依赖如图
《SpringBoot引入其他自定义SpringBoot》
在测试Springboot中添加依赖,并刷新maven

<dependency>
  <groupId>com.ndd</groupId>
    <artifactId>common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

扫描mapper和组件

需要在DemoApplication.java中添加mapper扫描和组件扫描(引入的和当前的都得扫描)
《SpringBoot引入其他自定义SpringBoot》

@SpringBootApplication
@MapperScan({ "com.example.demo.mapper", "com.ndd.common.mapper"})
@ComponentScan({ "com.ndd.common", "com.example.demo"})
public class DemoApplication { 
    public static void main(String[] args) { 
        SpringApplication.run(DemoApplication.class, args);
    }
}

测试是否成功

在test包下添加测试
《SpringBoot引入其他自定义SpringBoot》
得到正确的结果
《SpringBoot引入其他自定义SpringBoot》
可以看出测试项目和自定义Springboot项目中的Mysql操作均有效

    原文作者:Nikola灬Tesla
    原文地址: https://blog.csdn.net/ndd1996/article/details/110916124
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞