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

用宝塔给远程网站做备份python源码之家

用宝塔给远程网站做备份,python源码之家,阜阳网站建设哪家好,延庆手机网站建设在 Spring 容器内拼凑 bean 叫做装配。装配 bean 的时候#xff0c;你是在告诉容器#xff0c;需要哪些 bean #xff0c;以及容器如何使用依赖注入将它们配合在一起。 理论上#xff0c;bean 装配的信息可以从任何资源获得#xff0c;包括属性文件#xff0c;关系数据库…在 Spring 容器内拼凑 bean 叫做装配。装配 bean 的时候你是在告诉容器需要哪些 bean 以及容器如何使用依赖注入将它们配合在一起。 理论上bean 装配的信息可以从任何资源获得包括属性文件关系数据库等但 XML 文件是最常见的 Spring 应用系统配置源 Spring 中的几种容器都支持使用 XML 装配 bean包括   --XMLBeanFactory   --ClassPathXMLApplicationContext   --FileSystemXMLApplicationContext   --XMLWebApplicationContext 其中我们常用的有 ClassPathXMLApplicationContextFileSystemXMLApplicationContext 两种。   在 XML 文件中配置 bean 包括以下几个方面   1. 添加 bean   2. 配置 bean 属性     2.1 手动配置       2.1.1 通过 setter 方法       2.1.2 通过 constructor     2.2 自动配置   下面我们来添加 bean并通过 setter 方法来对 bean 的属性来进行配置   首先先写两个 bean 分别是 Person 和 Address 其中 Person 是依赖于 Address 的。下面附上代码 package com.spring.xmlBean;public class Person {private String name;private int age;private Address address;public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}public Address getAddress() {return address;}public void setAddress(Address address) {this.address address;}public Person(String name, int age, Address address) {super();this.name name;this.age age;this.address address;}public Person() {super();}Overridepublic String toString() {return Person [name name , age age , address address ];}} Person 类 package com.spring.xmlBean;public class Person {private String name;private int age;private Address address;public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}public Address getAddress() {return address;}public void setAddress(Address address) {this.address address;}public Person(String name, int age, Address address) {super();this.name name;this.age age;this.address address;}public Person() {super();}Overridepublic String toString() {return Person [name name , age age , address address ];}} Address 类   类写完之后我们在 classpath 下创建一个 Spring Bean Configuration File 创建完 XML 文件之后我们开始在这个文件里配置 Bean。 首先第一步添加 bean ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd!-- 添加 Address 和 Person --bean idaddress classcom.spring.xmlBean.Address/beanbean idperson classcom.spring.xmlBean.Person/bean /beans Spring Bean Configuration File 在这里我们通过 bean/bean 节点来添加 bean 其中 class 属性代表 bean 的全类名 id 属性用来对 bean 进行标示在调用 bean 的时候会使用这个 id 名这个名字是唯一的在配置文件中不能有重复否则 Spring 会报错 添加完 bean 之后我们先来测试一下看能不能获取到这个 bean。我们先试着获取一下 Person package com.spring.test;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.spring.helloworld.HelloWorld; import com.spring.xmlBean.Person;public class TestMain {public static void main(String[] args) {// 创建 Spring 的 IOC 容器ApplicationContext ctx new ClassPathXmlApplicationContext(beanConfiguration-xml.xml);// 使用 getBean() 方法, 通过传入刚才的 id 名,来获取 bean, 但是这里返回的是一个 Object 对象, 所以要转型Person person (Person) ctx.getBean(person);// 打印 personSystem.out.println(person);} } TestMain 运行 main 方法控制台输出了以下信息 我们看到我们成功的获取到了 person但是person 中的属性是空的因为我们还没有配置他们只是单纯的把它们添加到容器里面 那么现在我们就来手动配置一下这两个 bean 前面讲过手动配置 bean 有两种方式一种是通过 setter 方法一种是通过 构造器constructor来配置。下面我们都试一下 1. 通过 setter 方法   首先需要注意的是若要通过 setter 方法来配置 bean 那么这个 bean 里面一定要有 setter 方法否则 Spring 会报错   下面我附上 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/beans http://www.springframework.org/schema/beans/spring-beans.xsd!-- 添加 Address 和 Person --bean idaddress classcom.spring.xmlBean.Addressproperty namecity value日照/propertyproperty nameprovince value山东/property/beanbean idperson classcom.spring.xmlBean.Personproperty namename valueLittle-Koala/propertyproperty nameage value18/property!-- 通过 ref 引用了 address 这个 bean --property nameaddress refaddress/property/bean /beans Spring Bean Configuration File 运行刚才测试用的那个 main 方法发现配置成功了 在配置的时候我们使用了 property name属性名  value值 /property 这个节点来对 bean 进行配置 其中我们的 person 中有一个 Address 属性它通过 ref 这个属性节点引用了 id 值为 address 的 bean 总结通过 setter 方法来配置 bean 我们使用 property 节点来进行配置但前提是这个 bean 要有 setter 方法。其中name 属性表示 bean 的属性名bean 的属性值可以通过 value 属性来直接设置也可以通过 ref 属性来引用其他的 bean   2. 通过构造器来进行配置   首先要注意的问题在配置之前要有自己的构造器。我们通过 constructor-arg/constructor-arg 这个节点来进行配置下面附上代码 bean idaddress classcom.spring.xmlBean.Addressconstructor-arg namecity value日照/constructor-argconstructor-arg nameprovince value山东/constructor-arg!-- property namecity value日照/propertyproperty nameprovince value山东/property-- /bean Spring Bean Configuration File 上面的 Address 这个 bean 换成了用构造器来配置运行的效果和上面是一样的 其中name 代码构造器中属性的名字value 代表值   刚才上面说了怎样配置 bean 还没有具体的讲怎么样从容器中获取 bean 获取bean分两步   1. 创建 IOC 容器   2. 从容器中获取 bean 下面附上代码 package com.spring.test;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.spring.helloworld.HelloWorld; import com.spring.xmlBean.Person;public class TestMain {public static void main(String[] args) {// 创建 Spring 的 IOC 容器ApplicationContext ctx new ClassPathXmlApplicationContext(beanConfiguration-xml.xml);// 使用 getBean() 方法, 通过传入刚才的 id 名,来获取 bean, 但是这里返回的是一个 Object 对象, 所以要转型Person person (Person) ctx.getBean(person);// 打印 personSystem.out.println(person);} } 怎样获取 Bean 这是刚才的那个测试类 其中 getBean( ) 方法可以通过传入 id 值来获取 IOC 容器中的 bean 也可以通过传入 Bean.class 来获取对应类型的对象   以上内容都是基础的内容还有一部分没有提到剩下的那些内容在以后的学习中会慢慢接触多读源码多看文档慢慢的就会了转载于:https://www.cnblogs.com/zyx1301691180/p/7665971.html
http://www.huolong8.cn/news/383088/

相关文章:

  • 重点培育学科建设网站厦门广告公司排名
  • 敖汉旗网站建设近期国际军事新闻
  • 网站基础服务网络营销推广8种方法
  • 建设银行手机网站公司网站建设精品
  • 做动画视频的网站有哪些北京国贸网站建设
  • 做校园文化展览的网站广州十大高端网站建设公司
  • 门户网站阳光警务执法办案查询seo推广宣传
  • 电子商城网站开发购物车企业网站建设运营方案
  • 百度怎么建立网站关键词seo优化服务
  • 如何查看网站备案哪里有学市场营销培训班
  • 北京网页设计制作网站免费简约ppt模板
  • 网站开发全栈工程师技能图个人网站备案条件
  • 国外做游戏的视频网站有哪些问题软文素材库
  • 怎么样做美术招生信息网站个人网站推广平台大全
  • centos7.2做网站windows 网站开发
  • 做神马网站快速排名深圳市住房城乡建设局网站
  • 开封网站建设流程与步骤企业站seo外包
  • 亿通网站建设广州城乡建设网站
  • 开鲁网站seo站长工具网站过期查询
  • 建好网站后最怎么维护网站怎样做淘宝客
  • 怎么建设网站让国外看工程公司取名字大全参考
  • 微信小程序 连接网站苏州网站建设 江苏千渡
  • 建设工程合同履行的原则seovip培训
  • 商城版手机网站制作asp.net网站开发模板
  • 建设银行瓶窑支行网站在线购物系统的分析与设计
  • 广西网站建设产品介绍微信公众号怎么做好看
  • 做么网站有黄网站平台建设论文
  • 网站用户模板apache 网站建设
  • 国内做的好看的网站网站服务器放置地
  • 小白如何搭建个人网站前端开发是干嘛