springboot @ComponentScan注解
@ComponentScan 告诉Spring
从哪里找到bean。
如果你的其他包都在@SpringBootApplication
注解的启动类
所在的包及其下级包,则你什么都不用做,SpringBoot
会自动帮你把其他包都扫描了。
如果你有一些bean
所在的包,不在
的包及其下级包,那么你需要手动加上启动类
@ComponentScan
注解并指定那个bean
所在的包。
@SpringBootApplication
@ComponentScan({"com.demo"})
public class Application {
private static final Logger LOG = LoggerFactory.getLogger(Application.class); public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setBannerMode(Banner.Mode.OFF);
app.setWebEnvironment(true);
app.run(args);
LOG.info("**************** Startup Success ****************");
}
}
springboot @ComponentScan注解的更多相关文章
- 005 Spring和SpringBoot中的@Component 和@ComponentScan注解
今天在看@ComponentScan,感觉不是太理解,下面做一个说明. 1.说明 ComponentScan做的事情就是告诉Spring从哪里找到bean 2.细节说明 如果你的其他包都在使用了@Sp ...
- SpringBoot的注解:@SpringBootApplication注解 vs @EnableAutoConfiguration+@ComponentScan+@Configuration
spring Boot开发者经常使用@Configuration,@EnableAutoConfiguration,@ComponentScan注解他们的main类, 由于这些注解如此频繁地一块使用( ...
- SpringBoot 常用注解
@SpringBootApplication 这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置. @Ena ...
- SpringBoot常用注解使用
1.RequestBody和ResponseBody注解 @RequestMapping(“url”),这里的 url写的是请求路径的一部分,一般作用在 Controller的方法上,作为请求的映射地 ...
- SpringBoot 常用注解(持续更新)
SpringBoot 常用注解 @SpringBootApplication @Bean @ComponentScan @ControllerAdvice @ExceptionHandler @Res ...
- 常见的springmvc、SpringBoot的注解
springMvc的常用注解 : @Controller :用于标记在一个类上,使用它标记的类就是一个springmcv Controller对象,分发处理器将会扫描使用了该注解 的类的方法,并检测该 ...
- 浅谈SpringBoot核心注解原理
SpringBoot核心注解原理 今天跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到零配置 ...
- SpringBoot常用注解总结
在SpringBoot框架中,注解做为一种隐式配置,极大的简化了之前xml文件的配置方式.SpringBoot中包含许多种类的注解,这里对在SpingBoot项目中经常使用到的一些注解的进行大致的归纳 ...
- SpringBoot(14)—注解装配Bean
SpringBoot(14)-注解装配Bean SpringBoot装配Bean方式主要有两种 通过Java配置文件@Bean的方式定义Bean. 通过注解扫描的方式@Component/@Compo ...
随机推荐
- 在vue项目中设置BASE_URL
在vue项目中设置BASE_URL 1.在config文件夹中新建global.js文件 const BASE_URL = 'http://192.168.1.62:8080/rest/' expor ...
- 如何将.sql文件导入到mysql的数据库中
首先通过cmd的net start mysql57 启动mysql的服务器 然后,输入命令:mysql -h 127.0.0.1 -u root -p来启动mysql服务 最后 上图画红圈的部分是.s ...
- PP: Deep r -th Root of Rank Supervised Joint Binary Embedding for Multivariate Time Series Retrieval
from: Dacheng Tao 悉尼大学 PROBLEM: time series retrieval: given the current multivariate time series se ...
- 解决laravel 429请求错误
429 Too Many Requests(过多请求) 用户在在指定的时间里发送了太多的请求.用于限制速率. 这是laravel的api访问频率 找出throttle 这个中间件,注释掉.429问题 ...
- Python Turtle模块的简单应用
时钟 import turtle as t import datetime as dt #画出背景 game = t.Screen() game.bgcolor("white") ...
- 浅析网页meta标签中X-UA-Compatible属性的使用
今天有一个做开发的朋友突然问你知道很多网站上面加入的X-UA-Compatible属性的意义么?其实这个在以前还专门花了一点时间来验证我自己的想法,结果也确实如自己所预想的那样,八九不离十,当然有一点 ...
- day27 综合架构 rsync备份服务
sync软件使用方法: rsync命令 1v4 a 本地备份数据 cp [root@nfs01 backup]# cp /etc/hosts /tmp [root@nfs01 backup]# ll ...
- Linux - Shell - 算术表达式 - 算数运算
概述 shell 中基于 $(()) 的 算数运算 背景 复习 shell 脚本 凑数吧 准备 环境 os centos7 1. 算数运算 代码 #!/bin/bash # $(()) 的数学运算, ...
- Java基本语法--关键字&标识符
本篇博客主要介绍了Java基本语法中的关键字.保留字和标识符. 关键字与保留字 关键字(keyword的定义及特点) ✄ 定义:被Java 语言赋予了特殊含义,用做专门用途的字符串 ✄ 特点:关键字中 ...
- IntelliJ IDEA常规配置教程
IntelliJ IDEA,是java编程语言开发的集成环境.IntelliJ在业界被公认为最好的java开发工具,尤其在智能代码助手.代码自动提示.重构.J2EE支持.各类版本工具(git.sv ...