怎样引入其他模块的类

问题
我想在servicec下面的三个模块中使用common模块下的common_utils和service_base下的类
解决方法
其中service_base也使用了common_utils模块下的类
在service_base(不是SpringBoot应用)的pom.xml中
<dependencies>
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>common_utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
然后在serviec模块的pom.xml中
<dependencies>
<dependency>
<groupId>com.atguigu</groupId>
<artifactId>common_utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
那个springboot的模块用到了common_utils的类,就在springboot启动类上加上@ComponentScan(basePackages = {"com.atguigu"})
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)//exclude = DataSourceAutoConfiguration.class ,默认不加载数据库,因为有一些模块不负责数据库任务。
@ComponentScan(basePackages = {"com.atguigu"})//扫描
public class VodApplication {
public static void main(String[] args) {
SpringApplication.run(VodApplication.class,args);
}
}
总结
修改pom文件,加上@ComponentScan(basePackages = {"包名"})注解
引入模块也可存在包含。
本文来自博客园,作者:NeverLateThanBetter,转载请注明原文链接:https://www.cnblogs.com/do-it-520/p/16583939.html
韶华易逝,不能虚度年华。
浙公网安备 33010602011771号