1.@Component:把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/> 2.@Autowired:Spring框架中进行对象注入 @Component public class Person { private String id; private String name; private String sex; //getter/setter省略 } @Service public class
1.在类上直接加注解@Component,那么这个类就直接注入到Spring容器中了 ,像@Contrloller,@Service这些本质上都是@Component, 2.@Configuration(或者@SpringBootConfiguration)放到类上,然后在类中的方法上加注解@Bean @SpringBootConfigurationpublic class UseConditionalOnBean { @Bean public User createBean(){ retur