天天看点

SpringBoot 将类加入ioc容器所有方式大全

下面的注解都是用在主配置类中,也就是加了@Configuration的类里面

①:通过@CompentScan + @Controller @Service @Respository @component,适用场景: 针对我们自己写的组件可以通过该方式来进行加载到容器中。

https://blog.csdn.net/pengweismile/article/details/94837512

②:通过@Bean的方式来导入组件 (适用于导入第三方组件的类)

https://blog.csdn.net/pengweismile/article/details/94863194

③:通过@Import来导入组件 (导入组件的id为全类名路径)

https://blog.csdn.net/pengweismile/article/details/94865064

④:通过实现FacotryBean接口来实现注册 组件 

https://blog.csdn.net/pengweismile/article/details/94870035

继续阅读