SpringBoot 是如何通过 @SpringBootApplication 扫描项目中的 Bean

Spring注解详解:@ComponentScan自动扫描组件使用 PersonConfig修改** 阅读详情

原因

首先因为 XXXXXXXApplication 附带 @SpringBootApplication 注解,而 @SpringBootApplication 注解的层次如下:

SpringBootApplication
----@Inherited
----@SpringBootConfiguration
--------@Configuration
----@EnableAutoConfiguration
--------@Inherited
--------@AutoConfigurationPackage
------------@Inherited
------------@Import(AutoConfigurationPackages.Registrar.class)
--------@Import(AutoConfigurationImportSelector.class)
----@ComponentScan
--------@Repeatable(ComponentScans.class)

实现

可以看到 @SpringBootApplication 继承 @ComponentScan 与 @Configuration 用处如下;
扫描方法开始流程:
在这里插入图片描述

主要观察黄色方块的方法,是具体扫描路径的地方,具体实现流程如下:
在这里插入图片描述

获取 File 目录下的所有以 class 为结尾的文件后,扫描工作就完成了, 剩下的就是 spring 判断是否要管理此类的逻辑(例如:该类是否存在 @Component )

SpringBoot 出现 Consider defining a bean of type ‘common.utils.SFTPUtil‘ in your configuration 问题解决方案 在模块B的某个接口中使用@Autowired注入了模块A中定义的bean 阅读详情

相关推荐

Abaqus滞回问题求解—浆锚连接装配式剪力墙滞回模拟

当下土木工程研究生,多数都在从事装配式混凝土构件安全或装配式混凝土构件连接节点力学性能的研究。研究这类问题,几乎脱离不开对有限元软件的使用,Abaqus求解能力非常强大,但模型处理能力相对较弱。装配式混凝土结构的有限元计算与传统现浇结构相比,其节点处理起来相对复杂,计算结果往往需要凸显出连接节点力学特性,所以对建模精程度的要求较高。所以向大家介绍一款工具—HyperMesh软件(一下简称Hm),它是专业的有限元前处理工具,用于处理装配式混凝土构件或连接节点有限元模型比较合适。这篇文章主要介绍如何利用Hm处理

qq_31918049的博客 2901

SpringBoot多模块项目组件扫描失效与Bean名冲突的深度解析与实战

本文深入解析了SpringBoot多模块项目中常见的组件扫描失效与Bean名冲突问题,提供了详细的解决方案和最佳实践。通过分析`@SpringBootApplication`、`@ComponentScan`等注解的优先级和使用技巧,帮助开发者有效管理多模块项目的包扫描和Bean命名,提升项目可维护性。

weixin_28704565的博客 263

基于Matlab-Simulink的大林算法控制系统设计与振铃消除实验

本文详细介绍了基于Matlab-Simulink的大林算法控制系统设计与振铃消除实验。通过分析纯滞后系统的控制难题,探讨大林算法在工业控制中的应用优势,并提供Matlab-Simulink环境搭建、控制器D(z)设计、振铃消除及仿真实验的完整流程。文章还对比了大林算法与PID控制的性能差异,为工程实践提供参考。

dropout6artist的博客 795

黑马springboot_p22_springboot自动配置_Enable注解原理

一个springboot工程如果想要访问另一个工程下的一个子类的方式: 1.@ComponentScan注解:扫描范围:当前引导类所在包及其子包,可以使用这个注解扫描另一个工程的类所在的包(前提是在pom.xml文件中引入了另一个工程的坐标)。缺点是比较麻烦,繁琐。 2.可以使用@Import注解,加载类。这些类都会被spring创建,并放入IOC容器(前提是在pom.xml文件中引入了另一个工程的坐标)。 例如:@Import(UserConfig.class) 3.可以对@Import注解进行封

xiaobaiyiming的博客 200

秋叶ComfyUI整合包:一键部署AI绘画工作流,解决环境配置难题

在AI绘画和生成式AI领域,Stable Diffusion作为开源的扩散模型,为图像生成提供了强大的技术基础。其核心原理是通过学习数据分布,对随机噪声进行逐步去噪,最终生成高质量的图像。这项技术的价值在于极大地降低了专业图像创作的门槛,并推动了AIGC(人工智能生成内容)在艺术设计、游戏开发、广告营销等场景的广泛应用。然而,其典型工作流实现工具ComfyUI,在实际部署中常因Python环境、PyTorch版本与CUDA驱动之间的复杂依赖关系而受阻,尤其是面对NVIDIA 30系、40系及未来50系等不同

优快云头条 668

腾讯云TDSQL MySQL版 - 开发指南兼容性

语言结构 分布式实例支持所有 MySQL 使用的文字格式,包括: String Literals Numeric Literals Date and Time Literals Hexadecimal Literals Bit-Value Literals Boolean Literals NULL Values String Literals String Literals 是一个 bytes 或者 characters 的序列,两端被单引号'或者双引号"包围,TDSQL MySQL版

weixin_43872058的博客 909

@ComponentScan注解扫描不到其他工程的@Component注解

在pom中引入了另一个工程的依赖,在启动类上也加了@ComponentScan注解,并且basePackages参数也写了,还是扫描失败。 原因是因为要引入的那个工程没有放在仓库中,所以扫描不到。 maven常用打包命令 1、mvn compile 编译,将Java 源程序编译成 class 字节码文件。 2、mvn test 测试,并生成测试报告 3、mvn clean 将以前编译得到的旧的 class 字节码文件删除 4、mvn pakage 打包,动态 web工程打 war包,Java工程打 jar

weixin_45068786的博客 3956

RealSense D455的标定并运行VINS-FUSION

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

qq_40186909的博客 2万+

使用@ComponentScan自动扫描组件并指定扫描规则

使用@ComponentScan自动扫描组件并指定扫描规则 @Repository、@Service、@Controller、@Component注解的类都会被扫描到,并自动注入到Spring容器中。 此时,我们分别创建BookDao、BookService以及BookController这三个类,并在这三个类中分别添加@Repository、@Service、@Controller注解,如下所示。 BookDao // 名字默认是类名首字母小写 @Repository public class Book

weixin_45723046的博客 1747

华为OD机试新系统真题【计算电动车续航里程】

华为OD机试 新系统真题【计算电动车续航里程】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【计算电动车续航里程】多语言题解。

qq_45776114的博客 780

手把手教你使用 YOLOv11/v8 算法 + PaddleOCR 算法完成车牌检测和车牌识别系统,AI智能体,毛玻璃系统,包括PaddlePaddle安装、数据集预处理、模型训练、AI大模型应用等

手把手教你使用 YOLOv11/v8算法 + PaddleOCR算法完成车牌检测和车牌识别系统,AI智能体,毛玻璃系统,包括PaddlePaddle安装、数据集预处理、模型训练、AI大模型应用等。车牌识别系统支持 蓝牌、绿牌、黄牌、双层车牌等车牌识别。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 2779

springcloud @ComponentScan 多模块 扫描其他模块

@ComponentScan添加扫描范围 @SpringBootApplication @ComponentScan(basePackages = {"com.xx"}) public class UserApplication { public static void main(String[] args) { SpringApplication.run(UserApplication.class, args); } } 在当前pom.xml引入需扫描包的pom.xml

Felix南南 3429

开源数字人、虚拟直播部署教程

对,你无看错,是欧美的。在直播带货案例里,我们把模型导入到ue4,我们给模型在ue4里预设了四个动作(站着、站着说话、坐着、坐着说话),三个表情(平静、开发、愤怒),三个镜头(全局、近矩说话、看显示器播放商品展示)。我们只需要把目标主播的直播给录制下来,提取样本数据,然后训练一个从粉丝的不同刺激的组合,到主播的不同响应方式的多元逻辑回归的数学模型参数即可。

南七小僧的学海无涯 4559

记录springCloud项目报错Description:Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.rib

创建springcloud项目之后 然后就正常启动 突然报错我曾咨询AI,他说让我检查关于检查依赖项和项目版本是否兼容的问题,但未能解决我的困惑。尽管按照此建议操作,我的问题依然存在。偶然间,我看到有人提到可能是启动类位置的问题。于是,我将启动类放入更深一级的目录,再次启动,问题便得以解决。虽然问题解决了,但是我百思不得其解,为什么这样就好了,然后去网上查询资料,发下如下解释,主要是因为springboot项目的自动扫描原因。注解默认会扫描启动类所在包及其子包。当你将启动类移动到更深层次的包下,例如。

m0_56353506的博客 891

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring Boot 多模块注入访问不到jar包中的Bean问题

文章目录Spring Boot 多模块注入访问不到jar包中的Bean问题1. 关于 Spring Boot 自动注入及组件扫描2. Spring Boot 中 @ComponentScan3. Spring Boot 中 @SpringBootApplication4. 回答开篇问题5. 补充说明:@AliasFor6. 参考文档 Spring Boot 多模块注入访问不到jar包中的Bean问...

从心初发 2万+

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

springboot项目启动时如何排除一个bean?

大家好,我是G探险者。使用springboot开发项目,我们有时候会排除一些项目里面用不到的bean,不然的话项目启动会报错,这种情况通常是发生在什么场景里呢,以及如何解决呢?今天咱们就聊一聊。springboot默认封装了很多的组件,并且把这些组件都进行了自动化配置封装。也就是说,只要是springboot项目,启动类在@SpringBootApplication注解下,在不需要单独配置bean的情况下,本项目所用到的bean在容器启动的时候都会被自动扫描并注入到IOC容器里。

G探险者的博客 2326

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

@SpringBootApplication注解

@SpringBootApplication注解 @SpringBootApplication注解:这个注解是 Spring Boot 项目的基石,创建 SpringBoot 项目之后会默认在主类加上。 @SpringBootApplication public class SpringSecurityJwtGuideApplication { public static void main(java.lang.String[] args) { SpringApplication

kernly01的博客 247

@SpringBootApplication扫描哪些包

@SpringBootApplication扫描哪些包 我下面的知识来自《Spring Boot 实战》 作者汪云飞。 Spring Boot会自动扫描@SpringBootApplication所在类的同级包,以及下级包里的所有BEAN,所以建议入口类放在最外层的包名下。

庸医2048的博客 2万+

SpringBoot 启动类 @SpringBootApplication 注解

@SpringBootApplication是SpringBoot项目的核心注解,目的是开启自动配置。 annotation 以下是@SpringBootApplication源代码的一部分: @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(excludeFi

weixin_45228526的博客 367

SpringBoot项目的Application启动类所在目录和@SpringBootApplication注解扫描目录(简单证明版)

通过简单的测试解释Springboot项目的Application启动类所在包指哪个和@SpringBootApplication注解的扫描目录

mjnhlqk的博客 1659

SpringBoot默认包扫描问题

@SpringBootApplication注解默认扫描路径是: 自动扫描主程序所在包及其下面的所有子包里面的组件在maven多模块项目中,如果想让扫描到,需要在子模块下面创建相同的包如:如果包名不同就需要使用@ComponentScan注解来扫描但是@ComponentScan注解只能扫描spring-boot项目包内的bean并注册到spring容器中spring.factories文件是帮助spring-boot项目包以外的bean(即在pom文件中添加依赖中的bean)注册到spring-boot

小草的博客 427

springboot扫描组件_多模块组件扫描在Spring Boot中不起作用

我有两个模块的网络和业务。我已将业务纳入网络。但是,当我尝试将业务到Web使用的服务接口包括在内时@autowired,它确实很实用org.springframework.beans.factory.NoSuchBeanDefinitionException。因此,基本上@SpringBootApplication无法扫描@Service来自业务模块。这很简单,我想念吗?如果我@Bean在@Spr...

weixin_39874269的博客 322

springboot @SpringBootApplication注解分析

@SpringBootApplication是一个复合注解,包括@ComponentScan,和@SpringBootConfiguration,@EnableAutoConfiguration。 @SpringbootConfiguration   说明这是一个配置文件类,它会被@ComponentScan扫描到。进入@SpringBootConfiguration源码发现它相当于@C...

王侯将象的博客 322

SpringBoot之引导类[Application]

SpringBoot的引导类是Boot工程的执行入口,运行main方法就可以启动项目。

一切总会归于平淡 3629

springboot bean覆盖注册的问题(allowBeanDefinitionOverriding配置)

springboot bean覆盖注册的问题-allowBeanDefinitionOverriding配置 问题描述问题分析1. allowBeanDefinitionOverriding配置2. bean加载顺序 问题描述 项目引用三方jar包,需要对@Configuration配置类中的某个bean进行重写。过程中遇到了bean已被注册异常、以及新加的bean不加载的问题。 问题分析 测试项目中的问题时,写了两个config,都注册了RestTemplate DefaultConfig package

weixin_38929589的博客 7117
上一篇: Linux 中的特殊权限 SUID, SGID , SBIT
Carey丶zsh
博客等级 码龄10年 15粉丝 47原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值