当前位置: 首页 > news >正文

网站开发 只要wordpress滑动注册

网站开发 只要,wordpress滑动注册,建站免费加盟,手动删除wordpress插件1.相同点 Resource和Autowired这两个注解的作用都是在Spring生态里面去实现Bean的依赖注入 2.不同点 2.1 Autowired 首先#xff0c;Autowired是Spring里面提供的一个注解#xff0c;默认是根据类型来实现Bean的依赖注入。 Autowired注解里面有一个required属性默认值是t…1.相同点 Resource和Autowired这两个注解的作用都是在Spring生态里面去实现Bean的依赖注入 2.不同点 2.1 Autowired 首先Autowired是Spring里面提供的一个注解默认是根据类型来实现Bean的依赖注入。 Autowired注解里面有一个required属性默认值是true表示强制要求bean实例的注入在应用启动的时候如果IOC容器里面不存在对应类型的Bean就会报错。当然如果不希望自动注入可以把这个属性设置成false。 Controller public class HelloController {Autowired(required true)private HelloService helloService;ResponseBodyRequestMapping(/hello)public String hello() {return helloService.hello();} }但是当项目有多个相同类型的Bean被定义时使用Autowired会报错 org.springframework.context.annotation.Configuration public class Configuration {Bean(hello1)public HelloService hello1() {return new HelloServiceImpl();}Bean(hello2)public HelloService hello2() {return new HelloServiceImpl();} }所以Spring启动的时候会提示一个错误大概意思原本只能注入一个单实例Bean但是在IOC容器里面却发现有多个导致注入失败。 Field helloService in com.zte.helloworld.contorller.HelloController required a single bean, but 3 were found:- helloServiceImpl: defined in file [D:\JavaWorkSpace\code\helloworld\target\classes\com\zte\helloworld\service\impl\HelloServiceImpl.class]- hello1: defined by method hello1 in class path resource [com/zte/helloworld/config/Configuration.class]- hello2: defined by method hello2 in class path resource [com/zte/helloworld/config/Configuration.class]Action: Consider marking one of the beans as Primary, updating the consumer to accept multiple beans, or using Qualifier to identify the bean that should be consumed 针对这个问题我们可以使用 Primary或者Qualifier这两个注解来解决。 Primary表示主要的bean当存在多个相同类型的Bean的时候优先使用声明了Primary的Bean。 Qualifier的作用类似于条件筛选它可以根据Bean的名字找到需要装配的目标Bean。 Controller public class HelloController {Autowired(required true)Qualifier(hello1)private HelloService helloService;ResponseBodyRequestMapping(/hello)public String hello() {return helloService.hello();} }2.2 Resource Resource是JDK提供的注解只是Spring在实现上提供了这个注解的功能支持。 它的使用方式和Autowired完全相同最大的差异于Resource可以支持ByName和ByType两种注入方式。 如果使用nameSpring就根据bean的名字进行依赖注入如果使用typeSpring就根据类型实现依赖注入。 如果两个属性都没配置就先根据定义的属性名字去匹配如果没匹配成功再根据类型匹配。两个都没匹配到就报错。 Controller public class HelloController {// Autowired(required true) // Qualifier(hello1) // private HelloService helloService;Resource(name helloService01)private HelloService01 helloService01;Resource(type HelloService02.class)private HelloService02 helloService02;ResponseBodyRequestMapping(/hello)public String hello() {return helloService02.hello();} }3.总结 Autowired是根据type来匹配Resource可以根据name和type来匹配默认是name匹配。Autowired是Spring定义的注解Resource是JSR 250规范里面定义的注解而Spring对JSR 250规范提供了支持。Autowired如果需要支持name匹配就需要配合Primary或者Qualifier来实现。
http://www.w-s-a.com/news/679126/

相关文章:

  • 跨境电商运营主要做什么静态网站如何做优化
  • 南充网站建设网站网站备案安全责任书是谁盖章
  • 怎么将网站设置为首页网站子目录怎么做
  • 做网站交互wordpress信息导出
  • 如何自己做企业网站做外贸登录国外网站
  • 郑州炫彩网站建设网站集约化建设调研报告
  • 2016年两学一做教育网站优良的定制网站建设制作商
  • 自己做网站需要哪些流程网站建设服务费如何做会计分录
  • 莆田建站培训用手机制作游戏的app软件
  • 中山建网站找哪家wordpress采集图片插件
  • 网站首页做后台链接有什么好用的模拟建站软件
  • 宁波有没有开发网站的公司网站上线除了备案还需要什么
  • 网站备案授权wordpress默认主体设置
  • 厦门微信网站广州推广策划公司
  • 集团公司网站开发asp网站怎么运行
  • 广州短视频网站开发东莞市建设信息网
  • 建设网站如果赚钱电脑可以做服务器部署网站吗
  • 网站建设的编程专门做面包和蛋糕的网站
  • 档案网站建设比较分析南京建站公司
  • 哪个网站可以做店招傻瓜式wordpress
  • 网站开发项目经理职责青岛模版网站建设
  • 企业建站哪个好网站建设所用程序
  • 网站建设seo视频定制图片软件
  • 404错误直接转向到网站首页四川省建筑施工企业人员考试平台
  • 手表电商网站智能展厅
  • 南海网站推广梅州做网站公司
  • 昆明专业网站建设公司成都外贸网站建设费用
  • php mysql网站开发项目公司网站宣传设计
  • 自己做网站服务器的备案方法怎么查网站点击量
  • 信息产业部icp备案中心网站织梦做双语网站