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

深圳家居网站建设公司wordpress修改页尾

深圳家居网站建设公司,wordpress修改页尾,百度人工服务,wordpress学校网站模板一、前言 Spring 容器是 Spring 框架的核心部分#xff0c;它负责管理和组织应用程序中的对象#xff08;Bean#xff09;。Spring 容器负责创建、配置和组装这些对象#xff0c;并且可以在需要时将它们提供给应用程序的其他部分。 Spring 容器提供了两种主要类型的容器它负责管理和组织应用程序中的对象Bean。Spring 容器负责创建、配置和组装这些对象并且可以在需要时将它们提供给应用程序的其他部分。 Spring 容器提供了两种主要类型的容器BeanFactory 和 ApplicationContext。BeanFactory 是最基本的容器提供了基本的 Bean 生命周期管理和依赖注入的功能。ApplicationContext 是 BeanFactory 的一个子接口它提供了更多的企业级功能例如国际化、事件传播、资源加载等。 在 Spring 中通常通过配置文件或注解来定义和配置 Bean。当 Spring 容器启动时它会根据配置的信息来实例化和初始化对象。 二、xml配置初步使用 2.1 添加依赖 创建maven项目并在pom.xml中添加Spring的依赖。 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdspring_01/artifactIdversion1.0/versiondependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.3.22/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.11/versionscopetest/scope/dependencydependencygroupIdch.qos.logback/groupIdartifactIdlogback-classic/artifactIdversion1.2.11/version/dependency/dependencies/project 2.2 xml方式配置bean 新建bean.xml文件,目录结构 bean.xml ?xml version1.0 encodingUTF-8? 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!-- 构造函数实例化--bean idemploy classcom.demo.entity.Employ!-- 没有构造函数的时候--!-- constructor-arg index0 valuehanzhe/--!-- constructor-arg index1 value18/--!-- property nameusername valuehanzhe/property--!-- property namepassword value18/property--/bean/beans 2.3 测试类查看效果 SpringTest.java package com.demo; /*** author zhe.han* date 2023/2/2 14:28*/ public class SpringTest {/*** xml形式的简单入门* p* 1instantiation with a constructor 构造函数实例化*/Testpublic void test1() {/*** 加载文件的方式使用resource加载文件**/ApplicationContext context new ClassPathXmlApplicationContext(classpath:/test1.xml);// ApplicationContext context new ClassPathXmlApplicationContext(file:E:\\study\\28spring\\spring_01\\src\\main\\resources\\test1.xml);Emp employ (Emp) context.getBean(employ);final String password employ.getPassword();final String username employ.getUsername();System.out.println(username);System.out.println(password);} } 三、实例化 Bean 官网中提到实例化bean有三种方式 3.1 默认的无参构造函数 bean.xml ?xml version1.0 encodingUTF-8? 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!--构造函数实例化bean --bean idemp classcom.demo.entity.Emp/bean /beans public class Emp {final Log log LogFactory.getLog(Emp.class);private String username;private String password;public Emp(String username, String password) {this.username username;this.password password;}public Emp() {log.info(构造方法实例化......);}Overridepublic String toString() {return Emp{ username username \ , password password \ };} } 测试类 Testpublic void test1() {/*** 加载文件的方式使用resource加载文件**/ApplicationContext context new ClassPathXmlApplicationContext(classpath:/test1.xml);Emp employ context.getBean(employ, Emp.class);log.info(employ);} debug跟踪源码了解实例化过程。 debug定位到这个方法中 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBeanInstance 最终执行到这个方法使用无参构造函数实例化bean // No special handling: simply use no-arg constructor. return instantiateBean(beanName, mbd); 3.2 静态工程方法 ?xml version1.0 encodingUTF-8? 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!-- 静态工厂实例化--bean idemploy2_2 classcom.demo.entity.Emp2 factory-methodcreateInstance/bean /beans/*** Bean的实例化** p* 2instantiation with a static Factory Method:静态工厂实例化* p*/Testpublic void test2() {ApplicationContext context new ClassPathXmlApplicationContext(classpath:/test2.xml);// 静态工厂实例化Emp2 employ context.getBean(employ2_2, Emp2.class);log.info(employ);} 断点调试 debug定位到这个方法中‘ org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBeanInstance  最终执行到这个方法使用无参构造函数实例化bean // 判断BeanDefination中是否有factory-method 这个属性 if (mbd.getFactoryMethodName() ! null) {return instantiateUsingFactoryMethod(beanName, mbd, args);} 3.3 实例工厂方法 test3.xml ?xml version1.0 encodingUTF-8? 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!-- the factory bean, which contains a method called createInstance() --bean idserviceLocator classcom.demo.factory.DefaultServiceLocator/bean!-- the bean to be created via the factory bean --bean idemploy3factory-beanserviceLocatorfactory-methodcreateEmploy2_3Instance//beans DefaultServiceLocator public class DefaultServiceLocator {final static Log log LogFactory.getLog(Emp2.class);private static Emp2 employ new Emp2();public Emp2 createInstance() {employ.setPassword(password);employ.setUsername(username);log.info(实例工厂方法);return employ;}} 断点发现实例化流程和静态工厂方法一样 四、注解方式配置bean 4.1 使用Configuration 和Bean配置  // Configuration 作为配置类Bean 用于实例化、配置、初始化Spring的bean对象 AppConfig Configuration public class AppConfig {/*** 等价于在xml中配置** beans* bean idmmp classcom.demo.entity.Emp/* /beans* return*/Beanpublic Emp emp() {return new Emp(zhang san, 123456);}}/*** 注解方式配置spring的bean*/Testpublic void test4() {ApplicationContext context new AnnotationConfigApplicationContext(AppConfig.class);Emp bean context.getBean(Emp.class);log.info(bean);} 最终的实例化方法和静态工厂、工厂实例化方法一致。 以上就是Spring的初步使用和Bean的实例化的方法的了解。
http://www.yutouwan.com/news/213000/

相关文章:

  • 珠海摥园网站建设国外对旅游网站建设的现状
  • 枣强网址建站电脑网站设计页面
  • 网站尺寸大小深圳设计公司vi设计模板
  • 建设监理协会网站wordpress注册添加验证码
  • 网站锚文本使用查询手机网址大全123客户端下载
  • 秦皇岛网站推广价钱小程序开发平台哪家好
  • 网站制作cms嘉兴网站排名
  • 广州网站优化工具北京房产网官网
  • 个人建网站运营.鄂尔多斯网站网站建设
  • 搜狗站长平台打不开一个网站的首页设计ps
  • 视频网站自己做服务器app开发 网站建设
  • 制作公司网站的费用科技公司排名
  • 关于美术馆网站建设的方案为什么做网站必须用服务器
  • 英文网站建设深圳济南网站建设 选搜点o
  • 为什么做腾讯网站企业品牌logo设计
  • 阿升网站免费学设计网站改版方案策划书
  • 网站制作教程迅雷下载网店推广有哪些
  • 网站建设网络推广平台网站关于我们页面设计
  • 百度收录公司网站wordpress后台账户密码登不进
  • 计算机 网站开发 文章百度网页版官网首页
  • 深圳网站建设服务哪个便宜啊柳市网站建设哪家好
  • 网站建设合同怎么写定制网站制作费用
  • 首页关键词是不是一个网站的核心关键词所在企业邮箱怎么申请免费的
  • 学院网站设计案例设计公司的网站建设
  • 商务型网站建设做网站公司那家好
  • 江苏备案网站名称html代码小游戏
  • 赤峰市建设网站建站多少钱一个
  • 建外贸企业网站校园网络建设
  • 太原网站制作小程序手机网站绑定域名是什么意思
  • 网站建设图片教程衡阳网站优化公司