理解spring中AutoWire,Reource,以及Service等注解
来源:互联网 发布:淘宝宝贝链接 编辑:程序博客网 时间:2024/04/27 13:30
在Spring中由于xml配置的不方便,我们一般会采用注解提高开发速度。这次重点讲几个注解。
Service注解:
在不指定bean的Id时,bean的Id首字母小写。例如:LoginService,他创建的bean就是loginService,当然也可以指定bean的Id。
这种场景一般是有多个Service实现了某个接口,那么注入的时候就不能用AutoWire了,而是用Resource(name=”xxxx”)
而bean命名方式为:LoginService(“xxxx”)
Component注解和Service注解差不多,也可以指定bean的Id.
一般来说,controller和responsbody都只会有一个,这时候采用AutoWire进行注入就行了
AutoWire注解:按照类型进行注入,比如:你之前创建了一个Cat类的bean,这时候用AutoWire,会将该类型注入。
Resource注解:在不指定bean的Id时,会按照类型进行注入。如果指定了bean的Id,会注入;如果指定了bean的Id,但是找不到,会报错。
阅读全文
0 0
- 理解spring中AutoWire,Reource,以及Service等注解
- Spring中的注入注解Resource/Autowired以及配置文件中default-autowire参数详解
- spring annotation注解 autowire
- spring注解之@service等
- Spring中autowire属性
- Spring中autowire
- Spring中autowire属性
- Spring中autowire属性
- Spring中default-autowire与autowire区别
- Spring中@Autowired注解,@Resource注解和xml default-autowire区别
- Spring中Autowired注解,Resource注解和xml default-autowire工作方式异同
- Spring中Autowired注解,Resource注解和xml default-autowire工作方式异同
- Spring中@Autowired注解,@Resource注解和xml default-autowire区别
- Spring注解@Resource和@Autowire的区别
- Spring注解@Resource和@Autowire的区别
- Spring中autowire="byName"
- spring中@Autowire用法解释
- spring中@autowire与@resource
- Redis学习笔记(3)hash的读写
- JSONObject使用方法详解
- ubuntu caffe 编译
- 第27篇:Angular中的$q的形象解释及深入用法
- post发送请求
- 理解spring中AutoWire,Reource,以及Service等注解
- python3 多继承和MRO顺序
- OWL文件和protege的关系(加深理解版)
- 微信开放平台修改微信分享的小图标后,移动端显示的分享的小图标未改变的问题解决
- Elasticsearch、Logstash、Kibana、Filebeat的使用总结
- Broadcasts详解
- 线程和Service区别
- iOS出现NSString* class_name = ***之类的错误的解决方法
- android面试总结1