spring-boot @Component和@Bean的区别详解
1、@Component是用在类上的
@Component publicclassStudent{ privateStringname="lkm"; publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } }
2
@Configuration publicclassWebSocketConfig{ @Bean publicStudentstudent(){ returnnewStudent(); } }
如果你想要将第三方库中的组件装配到你的应用中,在这种情况下,是没有办法在它的类上添加@Component注解的,因此就不能使用自动化装配的方案了,但是我们可以使用@Bean。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。