被扫描的包下面的类如果被下面注解,则被创建加入到IOC中去

@Component:没有明确的角色

@Service:业务层角色

@Repository:持久层角色

@Controller:控制层角色

 

默认情况下,spring扫描“配置类(....Application)所在包”及“主类所在包的子包”,被扫描的会被注解成为IOC的Bean

比如:下面主类所在包是 com.xx, 所以com.xx、com.xx.controller和com.xx.po包都会被扫描,

SpringBoot入门04-组件扫描ComponetScan

 

 不能被spring默认扫描的包,可以使用注解@ComponentScan来指定被扫描,@ComponentScan是必须放在配置类上

SpringBoot入门04-组件扫描ComponetScan

 

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-06-25
  • 2021-08-25
  • 2021-11-29
  • 2022-01-28
  • 2021-06-06
  • 2022-12-23
猜你喜欢
  • 2021-06-19
  • 2021-12-23
  • 2022-12-23
  • 2021-06-02
  • 2021-11-08
  • 2021-10-13
相关资源
相似解决方案