刚刚开始学习spring boot,在application中忘记加上@componentscan,倒置web请求一直没有都是404,@componentscan的作用如下:

@ComponentScan告诉Spring 哪个packages 的用注解标识的类 会被spring自动扫描并且装入bean容器。

例如,如果你有个类用@Controller注解标识了,那么,如果不加上@ComponentScan,自动扫描该controller,那么该Controller就不会被spring扫描到,更不会装入spring容器中,因此你配置的这个Controller也没有意义。

@componentscan注解的用法和作用的更多相关文章

  1. Spring @Autowired、@Resource、@Required、@Component、@Repository、@Service、@Controller注解的用法和作用

    Spring @Autowired,@Resource,@Required注解的用法和作用 Spring中 @Autowired标签与 @Resource标签 的区别 Spring注解@Compone ...

  2. Spring源码分析-从@ComponentScan注解配置包扫描路径到IoC容器中的BeanDefinition,经历了什么(一)?

    阅前提醒 全文较长,建议沉下心来慢慢阅读,最好是打开Idea,点开Spring源码,跟着下文一步一步阅读,更加便于理解.由于笔者水平优先,编写时间仓促,文中难免会出现一些错误或者不准确的地方,恳请各位 ...

  3. Spring学习总结(6)-@Component和@ComponentScan注解

    参考文档:https://docs.spring.io/spring/docs/5.2.0.RELEASE/spring-framework-reference/core.html#beans-ste ...

  4. @Transactional注解事务不起作用

    @Transactional注解事务不起作用 问题:今天在项目中碰到一个事务问题,使用@Transactional注解事务,抛出异常不会滚. 解决一:https://blog.csdn.net/u01 ...

  5. 005 Spring和SpringBoot中的@Component 和@ComponentScan注解

    今天在看@ComponentScan,感觉不是太理解,下面做一个说明. 1.说明 ComponentScan做的事情就是告诉Spring从哪里找到bean 2.细节说明 如果你的其他包都在使用了@Sp ...

  6. @ComponentScan 注解

    在配置类上添加 @ComponentScan 注解.该注解默认会扫描该类所在的包下所有的配置类,相当于xml的 <context:component-scan>. @ComponentSc ...

  7. python学习第四十五天__name__用法和作用

    在python导入模块导入另外一个模块的时候,有时候只是想用其一个方法,会出现其他的方法也运行了,python用到__name__==‘__main__’ 解决问题,那么__name__用法和作用 1 ...

  8. 深入理解spring注解之@ComponentScan注解

    今天主要从以下几个方面来介绍一下@ComponentScan注解: @ComponentScan注解是什么 @ComponentScan注解的详细使用 1,@ComponentScan注解是什么 其实 ...

  9. springboot @ComponentScan注解

    @ComponentScan 告诉Spring从哪里找到bean. 如果你的其他包都在@SpringBootApplication注解的启动类所在的包及其下级包,则你什么都不用做,SpringBoot ...

随机推荐

  1. Spring boot with Apache Hive

      5.29.1. Maven <dependency> <groupId>org.springframework.boot</groupId> <artif ...

  2. Mongodb 集群加keyFile认证

    介绍 自从远古计绳结开始,数据库的存储就注定了今天的地位和多样性,Nosql的出现更是解决了现有的关系型数据库无法解决的一些难题,对高性能,灵活度,扩展性,海量数据的问题.随之而出现的高速内存索引数据 ...

  3. 很好用的log4j

  4. PHP 成长规划

    PHP程序员的技术成长规划 作者:黑夜路人(2014/10/15) 转:http://blog.csdn.net/heiyeshuwu/article/details/40098043 按照了解的很多 ...

  5. Yii框架操作数据库的几种方式与mysql_escape_string

    一.Yii操作数据库的几种选择 1,PDO方式. $sql = "";//原生态sql语句 xx::model()->dbConnection->createComma ...

  6. set 续1

    --------siwuxie095             三.用 set 实现计算     语法: SET /A expression     /A 命令行开关指定等号右边的字符串为待计算的数字表 ...

  7. springboot中开发热部署(devtools)

    1.只需要在pom文件中引入devtools的依赖即可 <dependency> <groupId>org.springframework.boot</groupId&g ...

  8. Associate File Type with Qt In Mac Os and Win

    Win Registry Question One day, my boss want me to finish one function which let the users can double ...

  9. juniper交换机配置

    1.链接串口配置: minicom -s ```bash Serial port setup  A -    Serial Device      : /dev/ttyS1               ...

  10. PHP逻辑运算符中的and和&&以及or和||是有区别的

    下图是PHP的逻辑运算符: 看图中and和&&都是“与”,而or和||都是“或”,初开起来没有区别,但实际上这里面有一个优先级别的区别,即: &&和||的优先级别要高于 ...