被掃描的包下面的類如果被下面注解,則被創建加入到IOC中去
@Component:沒有明確的角色
@Service:業務層角色
@Repository:持久層角色
@Controller:控制層角色
默認情況下,spring掃描“配置類(....Application)所在包”及“主類所在包的子包”,被掃描的會被注解成為IOC的Bean
比如:下面主類所在包是 com.xx, 所以com.xx、com.xx.controller和com.xx.po包都會被掃描,
不能被spring默認掃描的包,可以使用注解@ComponentScan來指定被掃描,@ComponentScan是必須放在配置類上