怎样引入其他模块的类

问题

我想在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 = {"包名"})注解
引入模块也可存在包含。

posted @   NeverLateThanBetter  阅读(55)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示