springBoot bean注入

Posted N神3

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springBoot bean注入相关的知识,希望对你有一定的参考价值。

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 personService{
 @Autowired
 Person person;
 //方法省略
}

 

以上是关于springBoot bean注入的主要内容,如果未能解决你的问题,请参考以下文章