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

电子商务网站建设与运营 说课网站开发常用技术

电子商务网站建设与运营 说课,网站开发常用技术,食品网站建设建议,酒店机票搜索量暴涨看到一篇写的很好的 Spring Bean 生命周期的博客#xff1a;一文读懂 Spring Bean 的生命周期#xff0c;在此写个简单的 Bean 进行验证。 1. 创建Springboot项目 基于 springboot 的2.1.8.RELEASE 创建一个简单项目#xff0c;只添加 spring-aop 包以引入spring依赖。 一文读懂 Spring Bean 的生命周期在此写个简单的 Bean 进行验证。 1. 创建Springboot项目 基于 springboot 的2.1.8.RELEASE 创建一个简单项目只添加 spring-aop 包以引入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/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.1.8.RELEASE/versionrelativePath//parentgroupIdcom.xxx.springtest/groupIdartifactIdsprint-test/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependencies!-- 只添加一个 aop 包以引入spring依赖 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId/dependency/dependencies/project2. 定义 TestBean 我们定义一个名为类型为TestBean名为testBean的测试 bean。 package com.xxx.springtest.lifecycle;import org.springframework.beans.BeansException; import org.springframework.beans.factory.*; import org.springframework.context.*; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; import org.springframework.util.StringValueResolver;import javax.annotation.PostConstruct; import javax.annotation.PreDestroy;/*** 测试验证 bean实现了各个 *Aware 接口和 InitializingBean#afterPropertiesSet、DisposableBean#destroy 接口* 此外除添加了由 PostConstruct 和 PreDestroy 注解标注的方法外* 还添加了自定义初始化 init()方法该方法名在用 Bean 声明 testBean 时设置。*/ public class TestBean implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, EnvironmentAware,EmbeddedValueResolverAware, ResourceLoaderAware, ApplicationEventPublisherAware, MessageSourceAware,ApplicationContextAware, InitializingBean, DisposableBean {public TestBean() {System.out.println( TestBean 构造方法执行 );}/* Aware start */Overridepublic void setBeanName(String s) {System.out.println(4. BeanNameAware#setBeanName);}Overridepublic void setBeanClassLoader(ClassLoader classLoader) {System.out.println(5. BeanClassLoaderAware#setBeanClassLoader);}Overridepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException {System.out.println(6. BeanFactoryAware#setBeanFactory);}Overridepublic void setEnvironment(Environment environment) {System.out.println(7. EnvironmentAware#setEnvironment);}Overridepublic void setEmbeddedValueResolver(StringValueResolver stringValueResolver) {System.out.println(8. EmbeddedValueResolverAware#setEmbeddedValueResolver);}Overridepublic void setResourceLoader(ResourceLoader resourceLoader) {System.out.println(9. ResourceLoaderAware#setResourceLoader);}Overridepublic void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {System.out.println(10. ApplicationEventPublisherAware#setApplicationEventPublisher);}Overridepublic void setMessageSource(MessageSource messageSource) {System.out.println(11. MessageSourceAware#setMessageSource);}Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {System.out.println(12. ApplicationContextAware#setApplicationContext);}/* Aware end */PostConstructpublic void postConstruct() {System.out.println(14. TestInitDestroyBean#postConstruct);}Overridepublic void afterPropertiesSet() throws Exception {System.out.println(15. InitializingBean#afterPropertiesSet);}/** 自定义初始化方法 */public void customInit() {System.out.println(16. TestInitDestroyBean#customInit);}/* 停止系统程序 */PreDestroypublic void preDestroy() {System.out.println(18. TestInitDestroyBean#preDestroy);}Overridepublic void destroy() {System.out.println(19. TestInitDestroyBean#destroy);}/** 自定义销毁方法 */public void customDestroy() {System.out.println(20. TestInitDestroyBean#customDestroy);} }3. 实现 BeanFactoryPostProcessor package com.xxx.springtest.lifecycle;import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.stereotype.Component;/*** 自定义 BeanFactoryPostProcessor该方法最先执行。*/ Component public class TestBeanFactoryPostProcessor implements BeanFactoryPostProcessor {Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {System.out.println(0. BeanFactoryPostProcessor#postProcessBeanFactory);} }4. InstantiationAwareBeanPostProcessor package com.xxx.springtest.lifecycle;import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; import org.springframework.stereotype.Component;/*** 自定义 InstantiationAwareBeanPostProcessor 处理。* 该接口的方法在实例化调用默认构造方法之前和之后执行。*/ Component public class TestInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {Overridepublic Object postProcessBeforeInstantiation(Class? beanClass, String beanName) throws BeansException {if (testBean.equals(beanName)) {System.out.println(1. InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation);}return InstantiationAwareBeanPostProcessor.super.postProcessBeforeInstantiation(beanClass, beanName);}Overridepublic boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {if (testBean.equals(beanName)) {System.out.println(2. InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation);}return InstantiationAwareBeanPostProcessor.super.postProcessAfterInstantiation(bean, beanName);}Overridepublic PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {if (testBean.equals(beanName)) {System.out.println(3. InstantiationAwareBeanPostProcessor#postProcessProperties);}return InstantiationAwareBeanPostProcessor.super.postProcessProperties(pvs, bean, beanName);} } 5. 实现 BeanPostProcessor package com.xxx.springtest.lifecycle;import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.stereotype.Component;/*** 自定义 BeanPostProcessor 处理。* 两个方法分别在自定义初始化方法之前和之后执行。*/ Component public class TestBeanPostProcessor implements BeanPostProcessor {Overridepublic Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {if (testBean.equals(beanName)) {System.out.println(13. BeanPostProcessor#postProcessBeforeInitialization);}return bean;}Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {if (testBean.equals(beanName)) {System.out.println(17. BeanPostProcessor#postProcessAfterInitialization);}return bean;}}6. 配置 testBean package com.xxx.springtest.lifecycle;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** Bean 生命周期测试 Configuration*/ Configuration public class TestBeanLifecycleConfig {Bean(initMethod customInit, destroyMethod customDestroy)public TestBean testBean() {return new TestBean();} }7. 创建启动类 package com.xxx.springtest;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication(scanBasePackages {com.xxx.springtest}) public class SprintTestApplication {public static void main(String[] args) {SpringApplication.run(SprintTestApplication.class, args);} }运行并查看执行顺序 源码 https://gitee.com/liuweibing/spring-test-lifecycle
http://www.pierceye.com/news/114119/

相关文章:

  • 服务器网站源码在哪建筑电工证
  • 网站导航国外做名片网站
  • 效益型网站西安移动网站建设
  • 爱站工具查询深一集团的网站谁做的
  • 为网站网站做推广制作本地网页
  • 行业推广做哪个网站好wordpress升级后编辑器没有
  • 百度经验网站建设wordpress 获取插件目录
  • 班服定制的网站通过ip访问网站需要怎么做
  • 门户网站建设汇报如果在网上接网站建设项目
  • 网站开发文档是什么概念注册个体户
  • 双井做网站的公司app开发和网站开发价格
  • 电梯企业网站制作中山网站建设电话
  • 做网站推广哪些跨境电商平台企业
  • 域名注册网站推荐方案模板
  • 亚运村网站建设北京工商注册官网
  • sql2005做网站书店网站建设人员分配
  • 工商局网站怎么做股东实名认证石家庄网站建设公司怎么样
  • 做公众号的模版的网站国内网站做国外服务器
  • 做国际网站的上海高端网站公司wordpress 4.9.6 下载
  • 学校集约网站建设最牛餐饮营销手段
  • wordpress影视站网站太花哨
  • 青岛 机械 中企动力提供网站建设小说网站怎么做空间小
  • 通江县网站建设做网站到八方资源网怎么样
  • 国家网站建设ssh架构jsp网站开发
  • 浦东新区手机网站设计网络营销做得好的产品
  • 浙江市建设网站市场监督管理局电话举报电话
  • 企业网站的建设的功能定位菏泽百度推广公司电话
  • linux系统怎么做网站女生去住建局好不好
  • 自己搭建环境建设网站网站开发温州
  • 下沙做网站软件erp系统的主要功能