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

建搜索型网站网络连接

建搜索型网站,网络连接,oss cdn wordpress,城北区建设局网站1.具体的生命周期过程 bean对象创建#xff08;调用无参构造器#xff09; 给bean对象设置属性 bean对象初始化之前操作#xff08;由bean的后置处理器负责#xff09; bean对象初始化#xff08;需在配置bean时指定初始化方法#xff09; bean对象初始化之后操作调用无参构造器 给bean对象设置属性 bean对象初始化之前操作由bean的后置处理器负责 bean对象初始化需在配置bean时指定初始化方法 bean对象初始化之后操作由bean的后置处理器负责 bean对象就绪可以使用 bean对象销毁需在配置bean时指定销毁方法 IOC容器关闭 2.User类 package com.zh.spring.pojo;public class User {private Integer id;private String username;private String password;private Integer age;public User() {//调用无参构造器实例化System.out.println(生命周期1实例化);}public User(Integer id, String username, String password, Integer age) {this.id id;this.username username;this.password password;this.age age;}public Integer getId() {return id;}public void setId(Integer id) {//使用setter方法进行赋值System.out.println(生命周期2依赖注入);this.id id;}public String getUsername() {return username;}public void setUsername(String username) {this.username username;}public String getPassword() {return password;}public void setPassword(String password) {this.password password;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age age;}Overridepublic String toString() {return User{ id id , username username \ , password password \ , age age };}public void initMethod(){//初始化方法System.out.println(生命周期3初始化);}public void destroyMethod(){//销毁方法System.out.println(生命周期4销毁);} } 注意其中的initMethod()和destroyMethod()可以通过配置bean指定为初始化和销毁的方法 3.对应的bean bean iduser classcom.zh.spring.pojo.User init-methodinitMethod destroy-methoddestroyMethodproperty nameid value1/propertyproperty nameusername valueadmin/propertyproperty nameage value21/propertyproperty namepassword value123456/property/bean!-- 将bean的后置处理器放入IOC容器中--bean idmyBeanPostProcessor classcom.zh.spring.process.MyBeanPostProcessor/bean 注意初始化时需要通过bean的init-methodinitMethod属性指定初始化的方法       IOC容器关闭时销毁需要bean的destroy-methoddestroyMethod属性指定销毁的方法 4.测试类 public class LifeCycleTest {Testpublic void test(){//ConfigurableApplicationContext是ApplicationContext的子接口其中扩展了刷新和关闭ioc容器的方法 // ApplicationContext ioc new ClassPathXmlApplicationContext(spring-lifecycle.xml);ConfigurableApplicationContext ioc new ClassPathXmlApplicationContext(spring-lifecycle.xml);User user ioc.getBean(User.class);System.out.println(user);//要想关闭ioc容器没有直接的close方法要使用ConfigurableApplicationContextioc.close();} } 5.bean的后置处理器 bean的后置处理器会在生命周期的初始化前后添加额外的操作需要实现BeanPostProcessor接口且配置到IOC容器中需要注意的是bean后置处理器不是单独针对某一个bean生效而是针对IOC容器中所有bean都会执行。 public class MyBeanPostProcessor implements BeanPostProcessor {Overridepublic Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {//此方法在bean的生命周期初始化之前执行System.out.println(MyBeanPostProcessor----后置处理器postProcessBeforeInitialization);return bean;}Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {//此方法在bean的生命周期初始化之后执行System.out.println(MyBeanPostProcessor----后置处理器postProcessAfterInitialization);return bean;} } 运行结果
http://www.zqtcl.cn/news/682924/

相关文章:

  • 门户网站建设定做如何使用域名访问网站
  • 做网站后台运营这个工作怎么样建设网站销售
  • 两学一做网上答题网站做网站域名是赠送的吗
  • 江苏住房城乡建设厅网站WordPress上传Excel
  • 广州淘宝网站建设济南高新区网站建设
  • 如何注册一个网站长沙的科技公司
  • 温州网络公司网站建设永久免费云linux服务器网页
  • 中国教育网站官网网站建设是半年的持久战
  • 为什么营销型网站比普通网站建站贵常州seo排名收费
  • 商贸公司寮步网站建设极致发烧学网站建设基础
  • 二手汽车手机网站模板四川百度推广排名查询
  • 做火情监控网站需要用什么系统做一个网站多少费用
  • 成都建设网站首页贺州网站建设
  • 硚口区建设局网站海绵宝宝的网页设计html源代码
  • 旅游网站建设合同成年做羞羞的视频网站
  • 海门网站建设制作道德建设 网站
  • 苏州 规划建设局网站网页设计师培训费用图
  • 怎么做视频解析的网站QQ空间可以建设网站吗
  • 视频网站 php源码甘肃 网站建设
  • 响应式网站和自适应便宜做网站8818
  • 湖南网站建设mxtia网站建设的流程图
  • 西安网站开发公司电话装修设计网站有哪些
  • 多少钱网站建设个人主页网页设计教程
  • 嘉兴品牌网站建设网站开发项目拖延周期
  • 网站版面布局结构网站建设公司公司
  • 给新公司建网站中国互联网企业排名前十名
  • 中国建设银行网站会员用户名网站建设应列入啥费用
  • 网站上面的水印怎么做的广东网站建设公
  • 爱站网关键词长尾挖掘工具wordpress文章外链
  • 做视频剪辑接私活的网站网站商城系统设计