目录
自定义被引用的SpringBoot
创建普通Springboot项目
1.去除SpringBootApplication
2.去除Test模块
3.去除application.properties
下面是项目结构
修改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依赖
在pom.xml中添加自定义Springboot依赖
自定义依赖如图
在测试Springboot中添加依赖,并刷新maven
<dependency>
<groupId>com.ndd</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
扫描mapper和组件
需要在DemoApplication.java中添加mapper扫描和组件扫描(引入的和当前的都得扫描)
@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项目中的Mysql操作均有效