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

网站开发制作费入会计科目wordpress自动判断当前分类并获取tag标签

网站开发制作费入会计科目,wordpress自动判断当前分类并获取tag标签,深圳松岗网站建设,软文广告经典案例目录 BeanFactoryPostProcessor BeanDefinitionRegistryPostProcessor 使用一下Bean工厂后置处理器 定义包扫描范围 定义一个组件Bean 定义一个普通的类 自定义一个组件类实现Bean工厂后处理器 测试类 BeanFactoryPostProcessor 该接口是Spring提供的扩展点之一是一个…

目录

BeanFactoryPostProcessor

BeanDefinitionRegistryPostProcessor

使用一下Bean工厂后置处理器

定义包扫描范围

定义一个组件Bean

定义一个普通的类

自定义一个组件类实现Bean工厂后处理器

测试类


BeanFactoryPostProcessor

  • 该接口是Spring提供的扩展点之一
  • 是一个函数式接口,只有一个抽象方法
  • Spring会在合适的时机执行方法回调,并将bean工厂作为参数传递进去

既然把ConfigurableListableBeanFactory类型的bean工厂传递过来了,那么该类型中的方法我是不是就可以为所欲为地为自己所用了啊

package org.springframework.beans.factory.config;import org.springframework.beans.BeansException;// 函数式接口
@FunctionalInterface
public interface BeanFactoryPostProcessor {// 参数为bean工厂void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;}

BeanDefinitionRegistryPostProcessor

  • 是BeanFactoryPostProcessor的子接口
  • 自身提供了一个将BeanDefinitionRegistry作为参数传递进来的方法

把BeanDefinitionRegistry传递过来了,BeanDefinitionRegistry是用来管理BeanDefinition的,提供了一系列操作BeanDefinition的方法,那么我就可以操作Spring容器中的BeanDefinition了

package org.springframework.beans.factory.support;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;// 继承了BeanFactoryPostProcessor
public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {// 将BeanDefinitionRegistry作为参数void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException;}

使用一下Bean工厂后置处理器

定义包扫描范围

package spring.demo;import org.springframework.context.annotation.ComponentScan;// 扫描spring.demo及其子包
@ComponentScan("spring.demo")
public class SpringConfig {
}

定义一个组件Bean

package spring.demo;import org.springframework.stereotype.Component;// 这里添加了@Component注解
// Spring容器启动过程中通过ConfigurationClassPostProcessor解析@Component注解,将Cat类的BeanDefinitoon放入容器中
@Component
public class Cat {
}

定义一个普通的类

package spring.demo;// Dog类只是一个普通的Java类,没加任何注解
public class Dog {
}

自定义一个组件类实现Bean工厂后处理器

package spring.demo;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;@Component
public class CustomBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {@Overridepublic void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {// Dog类只是一个普通的类// 在这里我通过Spring的回调拿到BeanDefinitionRegistry// 通过BeanDefinitionRegistry将Dog类的定义信息放入Spring容器中GenericBeanDefinition beanDefinition = new GenericBeanDefinition();beanDefinition.setBeanClass(Dog.class);registry.registerBeanDefinition("dog", beanDefinition);}@Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {// Spring回调将beanFactory传递过来// 这里通过beanName从beanFactory中获取到对应的BeanDefinition信息BeanDefinition catBeanDefinition = beanFactory.getBeanDefinition("cat");String beanClassName = catBeanDefinition.getBeanClassName();// 这里打印出:spring.demo.CatSystem.out.println(beanClassName);}
}

测试类

package spring.demo;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class SpringMain {public static void main(String[] args) {// 启动Spring容器AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);// 从容器中获取beanName为cat的beanObject catBean = applicationContext.getBean("cat");// 这里打印出:spring.demo.Cat@4310d43System.out.println(catBean);// 从容器中获取beanName为cat的beanObject dogBean = applicationContext.getBean("dog");// 这里打印出:spring.demo.Dog@54a7079eSystem.out.println(dogBean);}
}

http://www.dtcms.com/a/497243.html

相关文章:

  • 新手学做网站这本书wordpress 后台链接
  • 站长之家最新网站怎样开网店
  • 曼朗策划网站建设室内设计效果图报价
  • 做广告在哪个网站做效果人流最多WordPress代码改silder
  • 怎么做wood网站教程淄博做网站的公司排名
  • 沈阳网站开发技术公司本机网站建设
  • java求职学习day42
  • 淘宝官方网站登录页面网站备案目的
  • wordpress+中文站天津做网站认准津坤科技
  • 【开题答辩实录分享】以《智慧工地管理服务系统》为例进行答辩实录分享
  • 必贝特开启申购,将在科创板上市,募资金额较需求缩水约5亿元
  • 郑州设计师网站大全做网站优化就是发文章吗
  • 手机微信网站怎么做的好广告联盟下载app
  • 网站建设模板下载免费官网网站建设收费
  • 网址百度刷排名网站优化宝
  • 网站建设详细教程视频冯耀宗seo博客优化
  • ie网站建设style wordpress 主题
  • .东莞网站建设wordpress指定分类文章作者时间
  • 自定义模板设计指南:打造属于你的个性化思维导图
  • 网站页面设计素材seo网站上线前分析
  • 网站开发技术总结网站版面风格
  • 企业网站建设公司制作平台网页设计实训报告结束语
  • 阿里小说网站模板网站备案负责人照片
  • 做网站开发 甲方提供资料外链发布工具下载
  • 视频网站亏钱为什么还要继续做宁波男科医院哪家比较好
  • 建设官方网站多少视频网站建设的意义论文
  • seo网站查询工具奉化商用关键词优化
  • 住建局建设工程质量监督站深圳电力建设公司
  • 如何使用网站模板建设网站做网站赚钱要多久
  • 如何判断网站是竞价站南通建设局网站