子项目@ComponentScan扫描另一个子项目的包

序言:首先子项目是继承同一个父项目的


package com.xuecheng.manage_cms_client;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;

/**
 * @author Huang
 * @version 1.0
 * @date 2020/4/4 11:20
 */
@SpringBootApplication
//如果不添加额外的扫描注解, 则本启动类只会扫描到该本包下的文件, 不会扫到引入项目的文件
@ComponentScan(basePackages={"com.xuecheng.manage_cms"})
public class Cms_client_Application {
    public static void main(String[] args) {
        SpringApplication.run(Cms_client_Application.class, args);
    }
}

在这里插入图片描述
这里@ComponentScan(basePackages={“com.xuecheng.manage_cms”})的作用是让Cms_client_Application主程序扫描到xc-server-manage-cms项目下的包,如果不添加此注解,则默认只能扫描自己项目下com.xuecheng下的包了

发布了86 篇原创文章 · 获赞 1 · 访问量 4329

猜你喜欢

转载自blog.csdn.net/qq_42039738/article/details/105307660