怎样引入其他模块的类
问题
我想在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
韶华易逝,不能虚度年华。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?