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

新的购物网站怎么做流量分析做网站时图片的分辨率是多少

新的购物网站怎么做流量分析,做网站时图片的分辨率是多少,在线做qq空间的网站吗,微信小程序游戏手游排行榜1. Spring Bean 生命周期概述 Spring 框架中,Bean 的生命周期是其核心机制之一。了解 Bean 的完整生命周期有助于开发者更好地控制对象的创建、初始化、使用和销毁过程,尤其是在需要扩展、增强或定制 Bean 行为时,如资源加载、AOP 代理、日志…

1. Spring Bean 生命周期概述

Spring 框架中,Bean 的生命周期是其核心机制之一。了解 Bean 的完整生命周期有助于开发者更好地控制对象的创建、初始化、使用和销毁过程,尤其是在需要扩展、增强或定制 Bean 行为时,如资源加载、AOP 代理、日志记录等。

Spring Bean 的生命周期通常包括以下阶段(以 Singleton 作用域 为例):

阶段描述可干预方式开发中可能的操作
1. 实例化通过反射创建 Bean 实例无需干预通常由 Spring 自动完成
2. 属性注入注入依赖属性(字段、构造器、setter)无需干预通过 @Autowired@Resource 注入依赖
3. 前处理(BeforeInit):

在初始化方法之前执行;

执行方法BeanPostProcessor#postProcessBeforeInitialization

实现BeanPostProcessor 接口修改 Bean 属性、创建代理、日志记录
4. 初始化方法执行 @PostConstructInitializingBean#afterPropertiesSet()、或 init-method使用注解或配置资源加载(如数据库连接)、校验逻辑、预处理
5. 后处理(AfterInit):

在初始化方法之后执行;

执行方法BeanPostProcessor#postProcessAfterInitialization

实现BeanPostProcessor 接口AOP 代理创建、权限控制、日志记录
6. 使用阶段Bean 已准备好,可供应用使用无需干预业务调用、依赖注入
7. 销毁方法容器关闭时执行 @PreDestroyDisposableBean#destroy()、或 destroy-method使用注解或配置资源释放(如关闭连接池、停止线程)

2. Spring Bean生命周期的代码演示

2.1 代码示例

step1. 定义一个 Bean

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;@Component
public class MyBean implements InitializingBean, DisposableBean {public MyBean() {System.out.println("1. MyBean 实例化");}public void initMethod() {System.out.println("4. init-method: 初始化方法");}@PostConstructpublic void postConstruct() {System.out.println("4. @PostConstruct: 初始化方法");}@Overridepublic void afterPropertiesSet() throws Exception {System.out.println("4. InitializingBean#afterPropertiesSet: 初始化方法");}@PreDestroypublic void preDestroy() {System.out.println("7. @PreDestroy: 销毁方法");}@Overridepublic void destroy() throws Exception {System.out.println("7. DisposableBean#destroy: 销毁方法");}
}

step2. 定义一个 BeanPostProcessor

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;@Component
public class MyBeanPostProcessor implements BeanPostProcessor {@Overridepublic Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {System.out.println("3. BeanPostProcessor#postProcessBeforeInitialization: " + beanName);return bean;}@Overridepublic Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {System.out.println("5. BeanPostProcessor#postProcessAfterInitialization: " + beanName);return bean;}
}

step3. 配置 Bean 的 init 和 destroy 方法(可选)

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig {@Bean(initMethod = "initMethod", destroyMethod = "destroy")public MyBean myBean() {return new MyBean();}
}

step4. 主启动类(Spring Boot 示例)

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;@SpringBootApplication
public class Application {public static void main(String[] args) {ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);MyBean myBean = context.getBean(MyBean.class);System.out.println("6. Bean 已使用");// 关闭容器以触发销毁方法context.close();}
}

启动主类后,控制台输出顺序(部分)示例

1. MyBean 实例化
3. BeanPostProcessor#postProcessBeforeInitialization: myBean
4. @PostConstruct: 初始化方法
4. InitializingBean#afterPropertiesSet: 初始化方法
4. init-method: 初始化方法
5. BeanPostProcessor#postProcessAfterInitialization: myBean
6. Bean 已使用
7. @PreDestroy: 销毁方法
7. DisposableBean#destroy: 销毁方法

2.2 注意事项

  • 多个初始化/销毁方法:Spring 支持多种方式定义初始化和销毁方法,按照以下优先级执行:
    • @PostConstruct > InitializingBean#afterPropertiesSet() > init-method
    • @PreDestroy > DisposableBean#destroy() > destroy-method
  • Bean 作用域影响
    • @Scope("prototype") 的 Bean 不会执行 destroy 方法,除非手动调用 destroy()
  • BeanPostProcessor 顺序:如果有多个 BeanPostProcessor,可通过 @Order 或实现 Ordered 接口控制执行顺序。

3. 总结

Spring Bean 的生命周期是一个清晰且可扩展的过程。通过理解每个阶段的功能和干预方式,开发者可以灵活地控制 Bean 的行为,实现诸如 AOP、日志、资源管理等高级功能。掌握生命周期不仅有助于调试,还能帮助构建更加健壮和可维护的 Spring 应用。相关应用场景举例如下:

场景使用阶段
日志记录BeanPostProcessor
资源加载初始化方法(@PostConstruct
代理对象创建postProcessAfterInitialization(AOP 实现)
数据库连接关闭销毁方法(@PreDestroy
权限控制postProcessBeforeInitialization

4.相关文档

BeanPostProcessor用法-笔记-CSDN博客

InitializingBean接口和@PostConstruct-笔记_postconstruct和initializingbean-CSDN博客

SpringBoot启动后自动执行方法的各种方式-笔记_springboot项目启动自动调用方法-CSDN博客

Spring的xxxAware接口工作原理-笔记-CSDN博客


文章转载自:

http://10KviwIx.mhmsn.cn
http://Q31nsaPj.mhmsn.cn
http://W3fIfool.mhmsn.cn
http://FecfJ6vb.mhmsn.cn
http://r9qFsnIl.mhmsn.cn
http://lBI9fZXZ.mhmsn.cn
http://xZ66ER1b.mhmsn.cn
http://868JvTgR.mhmsn.cn
http://0Zyjoq8U.mhmsn.cn
http://lh5uFQXd.mhmsn.cn
http://5IC7W2UR.mhmsn.cn
http://O9CiTKDk.mhmsn.cn
http://Uhs9cElt.mhmsn.cn
http://fMiUKwwv.mhmsn.cn
http://oCuIIKpJ.mhmsn.cn
http://goeKmpxi.mhmsn.cn
http://t9wOhp3V.mhmsn.cn
http://HLeh0tK8.mhmsn.cn
http://vf6YzFM1.mhmsn.cn
http://kc38EAA9.mhmsn.cn
http://YGF5K8nB.mhmsn.cn
http://EtkwwBuv.mhmsn.cn
http://Cxyn0Mdl.mhmsn.cn
http://kqQiHTEX.mhmsn.cn
http://EsoRHkc2.mhmsn.cn
http://BqaZjA6t.mhmsn.cn
http://61Xgomu9.mhmsn.cn
http://xONtMfiD.mhmsn.cn
http://yv7J5AhY.mhmsn.cn
http://ENshBbAb.mhmsn.cn
http://www.dtcms.com/wzjs/685824.html

相关文章:

  • 成品网站多少钱网站设计与开发范本
  • IP怎么屏蔽网站域名湘潭网站建设方案费用
  • 网站建设有免费的空间吗网络培训的感受
  • 医疗器械网站建设策划书桂林网站开发公司
  • 做防水网站网站关键词热度
  • 建设银行公积金网站提示udunseo培训价格
  • 网站建设赚钱信阳高端网站建设
  • 电子商务网站系统建设实训心得whois哪个网站好
  • 永久免费自助建站软件高价做单网站
  • 网站制作流程分为哪三步上海包装设计公司
  • 什么网站可以看到绵阳建设推广普通话奋进新征程演讲稿
  • 天津网站建设制作品牌公司网站建设longda
  • 河北远策网站建设wordpress 获取网址
  • 站长工具ping滨海新区建设网站
  • 青岛网站建设哪里好网站推广的基本方法为
  • 网站快捷按钮以什么方式做网站建设对公司来说重要吗
  • 百度网站主要提供的服务广西住房和城乡建设厅官方网站
  • 没有做网站地图影响大吗吗南阳网站建设培训
  • 天津机械网站建设模板sem竞价推广怎么做
  • 杭州注册公司昆明网络优化
  • wordpress搭建教育网站ps软件免费版在哪下载
  • 海南省住房和城乡建设厅官方网站湖北网络推广
  • 工信部网站备案变更品牌推广策划营销策划
  • 做网站最烂公司扶贫网站建设方案
  • 网站问题解决个人可以做彩票网站吗
  • 电子商务网站建设系统特点Wordpress 相同tag
  • 网站百度贴吧wordpress搭建ss
  • 网站开发主要技术路线wordpress博客类主题
  • 别人帮做的网站怎么修改xp 做网站服务器吗
  • 百度快照 查看指定网站理财网站如何做推广