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

做网站 郑州公司哪家好如何在百度推广自己

做网站 郑州公司哪家好,如何在百度推广自己,wordpress 鼠标 效果,保安公司网站如何做IoC,Inversion of Control 控制反转#xff0c;是一个过程。仅通过构造函数、工厂方法或在对象实例化后在对象实例上设置属性来定义其依赖关系。容器负责这些工作#xff0c;这个过程从本质上来说是bean本身的反向#xff0c;因此称为反向控制。 1 容器 负责实例化、配置及… IoC,Inversion of Control 控制反转是一个过程。仅通过构造函数、工厂方法或在对象实例化后在对象实例上设置属性来定义其依赖关系。容器负责这些工作这个过程从本质上来说是bean本身的反向因此称为反向控制。 1 容器 负责实例化、配置及装配bean。容器从配置元数据那获取该怎么实例化、配置及装配bean。而配置来源主要有三个1XML2java注释3java代码。xml比较常用。 Configuration // 将一个普通类标志为IoC容器 public class CustomConfig {Bean // 定义一个beanpublic User customUser() {return new User();} }private static void test1() {AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext(CustomConfig.class);User user context.getBean(User.class);System.out.println(user); } 上面代码展示了java代码配置bean的方式。通过AnnotationConfigApplicationContext来获取容器。 图 ApplicationContext的方法及实现类 BeanFactory 接口提供了管理Bean的方法而ApplicationContext继承了该接口并有以下扩展 1更容易与Spring 的aop集成。 2消息资源处理。 3事件发布。 4针对web项目提供了特定的子类。 图 ApplicationContext的方法及实现类 2 Bean 构成程序主干并由IoC容器管理的对象称为bean。 在模块化开发中不同模块的容器可能存在依赖了同一bean的bean。有时我们考虑到扩展或者在某个模块中有特定的命名规范所依赖的这个bean的命名可能会不同。 比如模块A、B依赖同一个数据源配置bean。 在模块A中该bean命名为datasourceA在模块B中命名为datasourceB。这时候需要用到别名。 !--数据源common.xml-- bean iddatasource classdao.BaseDao/!--模块A a.xml-- import resourcedao.xml/!—别名-- alias namedatasource aliasdatasourceA/ bean idteacherService classservice.TeacherServiceproperty namebaseDao refbaseDao/ /bean 2.1 实例化 xml配置中实例化bean有三种方式1构造函数2静态工厂方法3bean的工厂方法。 public class GoodsDao { }public class GoodsService {public GoodsDao makeGoodsDao() {return new GoodsDao();} }public class StaticFactory {public static GoodsService makeGoodsService() {return new GoodsService();} }beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsd default-lazy-inittrue!--构造函数实例化--bean idgoodsService classinstantiating.GoodsService/!--静态工厂实例化class为该工厂的类--bean idgoodsService2 classinstantiating.StaticFactory factory-methodmakeGoodsService/!--bean的工厂实例化--bean idgoodsDao factory-beangoodsService factory-methodmakeGoodsDao/ /beans 3 依赖 依赖是指对象在运行中需要用到的其他对象。在IoC中由容器负责注入。注入方式有两种1构造函数2set方法。 public class OtherDao { }public class ReportDao { }public class ReportService {private ReportDao reportDao;private String name;private Double num;public ReportService(ReportDao reportDao, String name, Double num) {this.reportDao reportDao;this.name name;this.num num;}private Properties dataProperties;private MapString, String stockInfoMap;private ListString links;private OtherDao otherDao;public void setDataProperties(Properties dataProperties) {this.dataProperties dataProperties;}public void setStockInfoMap(MapString, String stockInfoMap) {this.stockInfoMap stockInfoMap;}public void setLinks(ListString links) {this.links links;}public void setOtherDao(OtherDao otherDao) {this.otherDao otherDao;}Overridepublic String toString() {return ReportService{ reportDao reportDao , name name \ , num num , dataProperties dataProperties , stockInfoMap stockInfoMap , links links , otherDao otherDao };}public static void main(String[] args) {ApplicationContext applicationContext new ClassPathXmlApplicationContext(dependency.xml);ReportService reportService applicationContext.getBean(ReportService.class);System.out.println(reportService);} }beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsd default-lazy-inittruebean idreportDao classdependency.ReportDao/bean idreportService classdependency.ReportService !-- constructor-arg 为构造函数参数参数可以依赖其他bean,也可以是基本类似--constructor-arg namereportDao refreportDao/constructor-arg namename valuereportService层/constructor-arg namenum value103.4/ !-- set方法来注入参数-- !-- Properties类型--property namedataPropertiespropsprop keyhostlocalhost/propprop keyusernameadmin/propprop keypassword123/prop/props/property !-- Map类型--property namestockInfoMapmapentry keyname value中国平安/entry keystock value601318.sh//map/property !-- List类型--property namelinks !-- 空值--null //propertyproperty nameotherDao !-- 内部bean可以不要id或者name,不会被其他bean依赖--bean classdependency.OtherDao//property/bean /beans 3.1 depends-on与懒加载 容器创建一个bean时会先创建起依赖的bean。但是有时两个bean直接没有直接依赖但是希望在创建这个bean之前先创建其他的bean。可用depends-on来完成这个需求 bean idteacherDao classdao.TeacherDao depends-onuserDao,baseDao/ 在创建teacherDao这个bean之前会先创建userDao及baseDao这两个bean。 在容器中默认会在项目加载时把所有的bean都创建完成这样做的好处是某个bean的配置错误能在运行时被发现。但是有时不希望创建所有的bean希望当要使用这个bean时再来创建default-lazy-init  懒加载属性可以作用于全局的beans,也可以作用于单个的beans。当值为true时bean在第一次使用时才会被创建。 3.2 方法注入 假如bean1的某个方法在每次调用时都需要一个特定的bean2不是bean1的直接依赖即非bean1的字段。传统方法是可以在该方法中通过ApplicationContext获取bean2。这是这样加大了耦合度容器提供了Lookup标签来实现此类需求 public class Bean2 { }public class Bean1 {private final static ApplicationContext applicationContext new ClassPathXmlApplicationContext(method.xml);/*** 传统方式*/public void showBean2OfTradition() {Object bean2 applicationContext.getBean(bean2);System.out.println(bean2);}/*** Lookup 方法*/public Bean2 getBean2() {return null;}public static void main(String[] args) {Bean1 bean1 applicationContext.getBean(Bean1.class);bean1.showBean2OfTradition();System.out.println(bean1.getBean2());} }beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsd default-lazy-inittruebean idbean1 classmethod.Bean1 !-- 会覆盖原getBean2方法直接返回bean2--lookup-method namegetBean2 beanbean2//beanbean idbean2 classmethod.Bean2/ /beans 4 作用域 bean 也可以指定作用域生命周期Spring支持六种作用域。bean的scope属性来指定该bean的作用域。 singleton 默认作用域。不同容器生成的bean不同。 prototype 在同一容器中不同bean依赖的bean被创建的实例不同。 request 每次请求都会创建不同的bean。 session 每个session都会创建不同 bean。 application 每个servletContext生成不同的bean。 websocket 每个websocket连接生成不同的bean。 表 spring 的六种bean的作用域
http://www.pierceye.com/news/49358/

相关文章:

  • 最专业 汽车网站建设开家网站设计公司
  • 洛阳做网站排名做网站每年包多少流量
  • 网站建设的项目总结网站开发培训机构
  • 公司网站如何制作设计全国做网站的公司
  • 南海建设工程交易中心网站保定网站推广
  • 不备案的网站php就是做网站吗
  • 滨州j建设局网站投诉电话做影视网站被告怎么办
  • 东营做网站tt0546建站开始的前6个月多少外链最合适
  • 哪个网站做外单出口好asp.net学校网站整站系统源码
  • 网站做网站词怎么推广友妙招链接怎么弄
  • 学生网站建设总结报告网站建设wix
  • 霞浦网站建设春季高考网站建设
  • 网站上面的体验卡怎么做东莞电商网页设计
  • 重庆媒体网站建设单价wordpress采集站源码
  • ps做图 游戏下载网站wordpress修改搜索框
  • 网站建站公司公告网站策划的内容
  • 怎么创一个网站无锡做网站哪里好
  • 网站后期维护和管理怎么做国内优秀企业网站设计
  • 浙江常升建设有限公司网站如何做网站互链规则
  • 付网站建设费分录电子商务网站建设需要做好哪些准备
  • 加强网站网络安全建设方案毕业设计微信小程序开发
  • dedecms 营销网站模板免费下载湖北省城乡和住房建设厅官方网站
  • 网站设置的流程第一步应该2015网站备案教程
  • 茌平县建设局网站网站编程技术有哪些
  • 来雁新城建设投资公司官方网站易企网络网站建设
  • 天津建设网站需要的费用大型服装网站开发
  • 企业网站建设要多少网站设计报告模板及范文
  • wordpress 单本小说云优化seo软件
  • 洛阳制作网站公司中职电子商务专业就业方向
  • 搭建邮箱注册网站建设英文网站的请示