abc_begin

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

【springboot】修改扫描包(ComponentScan注解)

在springboot中默认的xxxApplication上面都是要加上@SpringBootApplication注解的

package com.oo2.oo2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Oo2Application {
public static void main(String[] args) {
SpringApplication.run(Oo2Application.class, args);
}
}

可以点@SpringBootApplication跟进去看一下

@ComponentScan(
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
)

默认就会扫描你这个类所在的包和下面的子包。如果我们想要扫描其他地方的包,就需要加上注解@ComponentScan,这个注解是支持扫描多个文件夹的,比如:

@ComponentScan({"com.dir1", "com.dir2"})

posted on   LastBattle  阅读(152)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示