天天看點

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

繼續閱讀