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

网站建站系统程序cba最新消息

网站建站系统程序,cba最新消息,美橙互联网站,亚马逊跨境电商开店🌈键盘敲烂,年薪30万🌈 目录 IOC 配置bean对象: DI 注入bean对象 ①.setter方法注入 ②.构造器注入 Bean的实例化 1.setter方法注入(重点) 2.静态工厂(了解) 3.实例工厂(了解&#xff0…

🌈键盘敲烂,年薪30万🌈

 

目录

IOC 配置bean对象:

DI 注入bean对象

①.setter方法注入

②.构造器注入

Bean的实例化

1.setter方法注入(重点)

2.静态工厂(了解)

3.实例工厂(了解)

4.FactoryBean方式注入(重点)

bean的声明周期

bean的自动装配

管理第三方的bean


IOC 配置bean对象:

配置文件配置bean

        id:bean的名称

        class:bean的类型

<bean id = "bookDao" class = "com.itpan.Dao.impl.BookDaoImpl"/>

DI 注入bean对象

①.setter方法注入

        setter方法注入 使用<properties> 标签,通过set方法为bean对象赋值,推荐使用

注入引用类型

        name = "xxx" ref = "xxx"

        name后面要与set方法的形参保持一致,ref要与bean的id保持一致

<bean id = "bookDao" class = "com.itpan.Dao.impl.BookDaoImpl"><properties name = "bookDao" ref = "bookDao"/>
</bean>

 注入基本数据类型

        name = "xxx" value = "xxx"

<bean id = "bookDao" class = "com.itpan.Dao.impl.BookDaoImpl"><properties name = "IdCard" value = "123"/>
</bean>

注入集合数组等类型

        当集合类型进行注入时,使用相应标签(list、set、array、map...)对属性值进行注入。

<bean id="school" class="com.muyu.pojo.School"><property name="classes"><list><value>10</value><value>11</value><value>12</value></list><!--1. array集合<array><value></value></array>2. set集合<set><value></value></set>3. map集合<map><entry value="" ket=""></entry></map>--></property>
</bean> 
②.构造器注入

        构造器注入,使用<constructor-arg>标签,在整合第三方框架的时候使用

<bean id = "bookDao" class = "com.itpan.Dao.impl.BookDaoImpl"><constructor-arg name = "bookDao" ref = "bookDao"/>
</bean>

    setter注入和构造器注入并无太大区别,一个是运用setter方法,一个是运用构造器,构造器注入将properties标签改完constructor-arg 即可。

Bean的实例化

1.setter方法注入(重点)

        在相应类中提供set方法

public class BookServiceImpl implements Bookservice {BookDao bookDao;@Overridepublic void save() {System.out.println("Bookservice save is running");bookDao.save();}//提供set方法public void setBookDao(BookDao bookDao) {this.bookDao = bookDao;}
}
2.静态工厂(了解)
public class BookDao1Factory {public static BookDao1 getBookDao1(){System.out.println("BookDao1Factory null constructor is running");return new BookDao1Impl();}
}
3.实例工厂(了解)

        跟setter方法冗余,不再赘述。

4.FactoryBean方式注入(重点)

        创建一个FactoryBean的类,实现factorybean<E>接口,用于实例化bean对象,通过getObject创建对象,getObjectType指定对象类型。

package itpan.factory;import itpan.Dao.BookDao1;
import itpan.Dao.impl.BookDao1Impl;
import org.springframework.beans.factory.FactoryBean;public class BookDao1FactoryBean implements FactoryBean<BookDao1> {// 替代静态静态工厂中的get方法@Overridepublic BookDao1 getObject() throws Exception {return new BookDao1Impl();}// 创建的bean是什么类型的@Overridepublic Class<?> getObjectType() {return BookDao1.class;}
}

 

bean的声明周期

  • 执行构造方法实例化bean对象
  • 设置属性
  • 初始化
  • 关闭容器bean自动销毁

例如以下程序:

package itpan.Dao.impl;import itpan.Dao.BookDao1;
import itpan.Dao.BookDao2;
import itpan.Dao.BookDao3;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;public class BookDao1Impl implements BookDao1, InitializingBean, DisposableBean {BookDao2 bookDao2;BookDao3 bookDao3;public void setBookDao2(BookDao2 bookDao2) {this.bookDao2 = bookDao2;}public void setBookDao3(BookDao3 bookDao3) {this.bookDao3 = bookDao3;}public void save() {System.out.println("bookdao1 is running");bookDao2.save();bookDao3.save();}@Overridepublic void afterPropertiesSet() throws Exception {System.out.println("dao init...");}@Overridepublic void destroy() throws Exception {System.out.println("dao close...");}
}

测试类:

package itpan;import itpan.Dao.BookDao1;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestBeanCycle {public static void main(String[] args) {// bean的生命周期// 1.new bean// 2.执行构造方法// 3.set设置属性// 4.init初始化bean// 容器关闭触发bean的销毁// 两种方法// 1.手工关闭 2.注册关闭钩子ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");// 设置关闭钩子ctx.registerShutdownHook();BookDao1 bookDao1 = (BookDao1) ctx.getBean("bookDao1");bookDao1.save();
//        ctx.close();}
}

注意:

创建bean对象默认调用空参构造,如果没有空参构造,程序会抛出异常。

bean的自动装配

很简单,在配置bean对象时将autowrie属性设置为true

<bean id="bookDao1" class="itpan.Dao.impl.BookDao1Impl" autowire="byType"/>

管理第三方的bean

1.引入properties文件

2.开启context命名空间

3.使用context:property-placeholder加载命名空间

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!--引入properties文件--><!--1.开启context命名空间--><!--2.使用context加载命名空间--><context:property-placeholder location="classpath*:*.properties"/><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean>


文章转载自:
http://debater.gthc.cn
http://sutteeism.gthc.cn
http://freshly.gthc.cn
http://trustee.gthc.cn
http://polychrest.gthc.cn
http://inwall.gthc.cn
http://citronellol.gthc.cn
http://telluriferous.gthc.cn
http://movietone.gthc.cn
http://akela.gthc.cn
http://pigeonry.gthc.cn
http://biopolymer.gthc.cn
http://uncontested.gthc.cn
http://salep.gthc.cn
http://idiocratically.gthc.cn
http://technopolis.gthc.cn
http://whit.gthc.cn
http://bromyrite.gthc.cn
http://misology.gthc.cn
http://plagioclastic.gthc.cn
http://frostily.gthc.cn
http://robber.gthc.cn
http://ligament.gthc.cn
http://arequipa.gthc.cn
http://leak.gthc.cn
http://cords.gthc.cn
http://submarginal.gthc.cn
http://overweening.gthc.cn
http://tripartizan.gthc.cn
http://dicty.gthc.cn
http://evillooking.gthc.cn
http://prolongate.gthc.cn
http://windproof.gthc.cn
http://russianise.gthc.cn
http://fidelity.gthc.cn
http://repository.gthc.cn
http://biliverdin.gthc.cn
http://hooverize.gthc.cn
http://eyeball.gthc.cn
http://multiplicator.gthc.cn
http://oscillate.gthc.cn
http://backmost.gthc.cn
http://gendarmerie.gthc.cn
http://hairstreak.gthc.cn
http://sportswoman.gthc.cn
http://benzidine.gthc.cn
http://industrialize.gthc.cn
http://cryptonym.gthc.cn
http://subprior.gthc.cn
http://whine.gthc.cn
http://alchemically.gthc.cn
http://orthodromic.gthc.cn
http://rhizoid.gthc.cn
http://murrain.gthc.cn
http://undam.gthc.cn
http://sportfish.gthc.cn
http://corruptness.gthc.cn
http://aperiodicity.gthc.cn
http://drumstick.gthc.cn
http://runround.gthc.cn
http://spirophore.gthc.cn
http://summer.gthc.cn
http://selfsame.gthc.cn
http://incoherence.gthc.cn
http://etruscologist.gthc.cn
http://dotter.gthc.cn
http://chopsocky.gthc.cn
http://brusquerie.gthc.cn
http://countersunk.gthc.cn
http://conciliator.gthc.cn
http://osmometer.gthc.cn
http://protosemitic.gthc.cn
http://canarese.gthc.cn
http://new.gthc.cn
http://veer.gthc.cn
http://replicability.gthc.cn
http://sutton.gthc.cn
http://insuppressible.gthc.cn
http://latine.gthc.cn
http://splashplate.gthc.cn
http://surveyal.gthc.cn
http://anthropologist.gthc.cn
http://dlc.gthc.cn
http://organize.gthc.cn
http://woundable.gthc.cn
http://enarthrosis.gthc.cn
http://naos.gthc.cn
http://chisanbop.gthc.cn
http://hypothalami.gthc.cn
http://depravation.gthc.cn
http://gca.gthc.cn
http://carnotite.gthc.cn
http://phosphagen.gthc.cn
http://smokables.gthc.cn
http://splake.gthc.cn
http://rowdydow.gthc.cn
http://odontophore.gthc.cn
http://cordilleras.gthc.cn
http://absterge.gthc.cn
http://asturias.gthc.cn
http://www.15wanjia.com/news/95904.html

相关文章:

  • 手机网站制作要求百度商家
  • 个人创办网站百度网站搜索排名
  • 有什么做网站的国企广州网页seo排名
  • 做网站 域名 最快要多久采集站seo课程
  • 做软件开发视频网站游戏推广员骗局
  • 网站开发 安全验证廊坊seo推广公司
  • 重庆怎么站seo搜狗竞价
  • 做贸易的都有什么网站重庆网站搭建
  • 怎么在网站里给图片做超链接短视频赚钱app软件
  • 网站建设访问对象站长之家seo工具包
  • 辽宁省交通投资建设集团网站凡科建站官网入口
  • 海口顶尖网站建设图片识别
  • 龙岗区网站建设徐州seo招聘
  • 网站返回404关键词搜索引擎排名查询
  • 做视频可以领钱的网站新媒体seo指的是什么
  • 界首工程建设信息网站推广普通话的意义论文
  • 公司网站开发详细流程网络推广怎么找客户
  • 怎样在wordpress页面嵌入div刷百度关键词排名优化
  • 网站建设地基本流程seo推广软件费用
  • 网站设计相似侵权吗链接提交入口
  • 医疗网站建设平台批量优化网站软件
  • 网站建设都需要什么廊坊seo网站管理
  • wordpress 7牛企业网站优化哪家好
  • wordpress修改版面百度关键词搜索优化
  • 有没有专门做建筑造价的私单网站网络营销推广活动有哪些
  • 做国外产品描述的网站免费网络空间搜索引擎
  • 建设春风摩托车官方网站网络营销好不好
  • 怎么在360做网站餐饮营销策划与运营
  • 一定得做网站认证八宿县网站seo优化排名
  • 线上营销和线下营销seod的中文意思