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

python 网站框架什邡门户网站

python 网站框架,什邡门户网站,wordpress教程哪本好,盘锦门户网站制作按类型自动装配可能多个bean实例的情况#xff0c;可以使用Spring的Qualifier注解缩小范围#xff08;或指定唯一#xff09;#xff0c;也可以指定单独的构造器参数或方法参数可用于注解集合类型变量例子#xff1a; package com.mypackage;import org.springframework.b…按类型自动装配可能多个bean实例的情况可以使用Spring的Qualifier注解缩小范围或指定唯一也可以指定单独的构造器参数或方法参数可用于注解集合类型变量例子 package com.mypackage;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier;public class MovieRecommender {AutowiredQualifier(main)private MovieCatalog movieCatalog;}package com.mypackage;import org.springframework.beans.factory.annotation.Qualifier;public class MovieRecommender {private MovieCatalog movieCatalog;public void prepare(Qualifier(main)MovieCatalog movieCatalog){this.movieCatalogmovieCatalog;}}PS应用于构造器的方法比较常用   XML文件中使用qualifier: ?xml version1.0 encodingUTF-8?beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.1.xsdcontext:component-scan base-packagecom.multibean/context:component-scan bean classcom.mypackage.MovieCatalogqualifier valuemain/qualifier/beanbean classcom.mypackage.MovieCatalogqualifier valueaction/qualifier/bean /beans如果通过名字进行注解注入主要使用的不是Autowired(即使在技术上能够通过Qualifier指定bean的名称)替代方式是使用JSR-250Resource注解它通过其独特的名称来定义来识别特定的目标这是一个与所声明的类型是无关的匹配过程因语义差异集合或Map类型的bean无法通过Autowired来注入因为没有类型匹配到这样的bean为这些bean使用Resource注解通过唯一名称引用集合或Map的beanAutowired适用于fieldsconstructorsmulti-argument method这些允许在参数级别使用Qualifier注解缩小范围的情况Resource适用于成员变量只有一个参数的setter方法所以在目标是构造器或者一个多参数方法时最好的方式是使用Qualifier例子 先定义一个BeanInterface接口 package com.multibean;public interface BeanInterface {}在定义两个实现类 package com.multibean;import org.springframework.stereotype.Component;Component public class BeanInterfaceImpl implements BeanInterface {}package com.multibean;import org.springframework.stereotype.Component;Component public class BeanInterface2Impl implements BeanInterface {}定义BeanInvoker实现Qualifier指定bean package com.multibean;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component;Component public class BeanInvoker {AutowiredQualifier(beanInterfaceImpl)private BeanInterface beanInterface;public void say(){if(null ! beanInterface){System.out.println(beanInterface.getClass().getName());}else{System.out.println(BeanInterface is null.);}}}单元测试 package com.multibean;import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class UnitTest {Testpublic void test(){ApplicationContext context new ClassPathXmlApplicationContext(classpath:spring-beansnnotation.xml);BeanInvoker beanInvoker (BeanInvoker)context.getBean(beanInvoker);beanInvoker.say();} }结果 七月 06, 2015 11:41:38 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext1e397bcb: startup date [Mon Jul 06 23:41:38 CST 2015]; root of context hierarchy 七月 06, 2015 11:41:38 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [spring-beansnnotation.xml] com.multibean.BeanInterfaceImpl     修改BeanInvoker package com.multibean;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component;Component public class BeanInvoker {AutowiredQualifier(beanInterface2Impl)private BeanInterface beanInterface;public void say(){if(null ! beanInterface){System.out.println(beanInterface.getClass().getName());}else{System.out.println(BeanInterface is null.);}}}结果 七月 06, 2015 11:43:38 下午 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext1e397bcb: startup date [Mon Jul 06 23:43:38 CST 2015]; root of context hierarchy 七月 06, 2015 11:43:38 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [spring-beansnnotation.xml] com.multibean.BeanInterface2Impl  转载于:https://www.cnblogs.com/JsonShare/p/4625753.html
http://www.zqtcl.cn/news/624597/

相关文章:

  • 圆通我做网站拉上海建站系统
  • 对于做网站有什么要求新闻发布会视频
  • 网站建设专业就业前景成都房产信息网 官网
  • 西宁网站建设公司排行网站查询域名ip解析
  • 柳州企业网站开发公司如何做网站首页图
  • 刷赞网站空间免费深圳网站制作公司排名
  • 网站内部优化策略获取网站的路径
  • 网站群 优点今天西安最新通告
  • 惠济免费网站建设设计制作的广告公司
  • 做一个网站建设装潢设计属于什么专业
  • 水处理网站源码注册销售公司流程和费用
  • 诸城网站建设0536s整站优化seo排名点击
  • 企业建设网站需注意哪些内容苏州网站怎么做
  • 浏览器打开网站网站推广软件工具
  • 网站主题编辑工具WordPress公司网站策划方案
  • 做旅游网站选什么空间搜索引擎优化策略有哪些
  • 网站备案多少钱安全网站建设与服务的关系
  • 手机端网页设计尺寸规范优化seo排名
  • 做网站业务提成多少厦门十大装修公司排名榜
  • 为什么用开源建站wordpress rss 插件
  • 语文建设投稿网站南昌做网站的公司多不多
  • 石家庄网站建设的公司功能性质网站
  • 企业网站主页模板装饰公司名字起名大全
  • 马鞍山网站设计价格如何在微信公众号内部做网站
  • 申请网站建设经费的报告生态建设网站
  • 建网站要多少钱用自己的服务器河北工程大学网站开发成本
  • 宁波网站建站公司商务网站模块设计时前台基础设施建设不包括
  • 徐州免费网站制作怎么用阿里云服务器搭建wordpress
  • php猎奇源码 织梦新闻视频图片八卦娱乐趣事资讯门户网站模板html代码表格
  • 南通做网站优化哪家好网页策划书 网站建设定位