[spring6: BeanPostProcessor BeanFactoryPostProcessor]-生命周期

BeanFactoryPostProcessor

BeanFactoryPostProcessor 接口允许在 Spring 容器初始化完所有的 bean 定义之后,但还未实例化任何 bean 时,修改应用上下文的内部 bean 工厂。通过实现 postProcessBeanFactory 方法,你可以覆盖或添加属性,甚至是对急切初始化的 beans 进行修改。

// AspectJWeavingEnabler, ConfigurationClassPostProcessor, CustomAutowireConfigurer, CustomEditorConfigurer, CustomScopeConfigurer, DeprecatedBeanWarner, EventListenerMethodProcessor, PlaceholderConfigurerSupport, PreferencesPlaceholderConfigurer, PropertyOverrideConfigurer, PropertyPlaceholderConfigurer, PropertyResourceConfigurer, PropertySourcesPlaceholderConfigurer
@FunctionalInterface
public interface BeanFactoryPostProcessor {/*** Modify the application context's internal bean factory after its standard* initialization. All bean definitions will have been loaded, but no beans* will have been instantiated yet. This allows for overriding or adding* properties even to eager-initializing beans.* @param beanFactory the bean factory used by the application context* @throws org.springframework.beans.BeansException in case of errors*/void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;}

BeanDefinitionRegistryPostProcessor

BeanDefinitionRegistryPostProcessor 接口继承自 BeanFactoryPostProcessor,允许在应用上下文的内部 bean 定义注册表初始化之后(但还未实例化任何 bean)修改 bean 定义。通过实现 postProcessBeanDefinitionRegistry 方法,可以在下一个后处理阶段之前,向容器中添加额外的 bean 定义。postProcessBeanFactory 方法默认是空实现,因为该接口主要关注 postProcessBeanDefinitionRegistry 方法。

// ConfigurationClassPostProcessor
public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {/*** Modify the application context's internal bean definition registry after its* standard initialization. All regular bean definitions will have been loaded,* but no beans will have been instantiated yet. This allows for adding further* bean definitions before the next post-processing phase kicks in.* @param registry the bean definition registry used by the application context* @throws org.springframework.beans.BeansException in case of errors*/void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException;/*** Empty implementation of {@link BeanFactoryPostProcessor#postProcessBeanFactory}* since custom {@code BeanDefinitionRegistryPostProcessor} implementations will* typically only provide a {@link #postProcessBeanDefinitionRegistry} method.* @since 6.1*/@Overridedefault void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {}}
实现类用途
AspectJWeavingEnabler启用 AspectJ 编织支持,通常与 Spring AOP 集成使用,用于支持 AspectJ 注解的织入。
ConfigurationClassPostProcessor处理 Spring 配置类(使用 @Configuration 注解的类),执行配置类的 Bean 定义处理。
CustomAutowireConfigurer允许注册自定义的自动注入限定符类型(如自定义注解),以扩展 Spring 的自动注入功能。
CustomEditorConfigurer为 Spring Bean 的属性类型注册自定义编辑器,以便在属性赋值时进行类型转换。
CustomScopeConfigurer配置 Spring 自定义作用域(例如,创建一个新的作用域或改变现有作用域的行为)。
DeprecatedBeanWarner提供警告,在 Spring Bean 配置中发现已弃用的 Bean 时发出警告。
EventListenerMethodProcessor处理使用 @EventListener 注解的方法,自动注册为 Spring 应用上下文中的事件监听器。
PlaceholderConfigurerSupport支持配置属性的占位符替换,通常用于加载属性文件并注入属性值到 Bean 中。
PreferencesPlaceholderConfigurer允许从 java.util.prefs.Preferences 中加载占位符属性,适用于 Java 的偏好设置。
PropertyOverrideConfigurer允许通过 XML 配置文件覆盖现有的 Bean 属性值,通常用于根据不同环境加载不同的配置。
PropertyPlaceholderConfigurer用于解析 properties 文件中的占位符并注入到 Spring 配置中的 Bean 属性。
PropertyResourceConfigurer处理并加载资源文件(如 .properties 文件)中的占位符替换,常用于外部配置文件的支持。
PropertySourcesPlaceholderConfigurer替代 PropertyPlaceholderConfigurer,支持在 Spring 4 中对 PropertySources API 的扩展。

BeanFactoryInitializer

BeanFactoryInitializer 接口用于初始化给定的 beanFactory。它定义了一个方法 initialize,接收一个类型为 F extends ListableBeanFactorybeanFactory 参数,允许实现类对该 beanFactory 进行启动或初始化设置。

public interface BeanFactoryInitializer<F extends ListableBeanFactory> {/*** Initialize the given bean factory.* @param beanFactory the bean factory to bootstrap*/void initialize(F beanFactory);}

BeanPostProcessor

BeanPostProcessor 接口允许在 Spring 容器初始化 bean 之前和之后对其进行自定义处理。通过实现这两个方法:postProcessBeforeInitializationpostProcessAfterInitialization,你可以在 bean 初始化的各个阶段修改 bean 实例或返回一个包装的版本。

// AbstractAdvisingBeanPostProcessor, AbstractAdvisorAutoProxyCreator, AbstractAutoProxyCreator, AbstractBeanFactoryAwareAdvisingPostProcessor, AdvisorAdapterRegistrationManager, AnnotationAwareAspectJAutoProxyCreator, AspectJAwareAdvisorAutoProxyCreator, AsyncAnnotationBeanPostProcessor, AutowiredAnnotationBeanPostProcessor, BeanNameAutoProxyCreator, BeanValidationPostProcessor, CommonAnnotationBeanPostProcessor, DefaultAdvisorAutoProxyCreator, ImportAwareAotBeanPostProcessor, InfrastructureAdvisorAutoProxyCreator, InitDestroyAnnotationBeanPostProcessor, JmsListenerAnnotationBeanPostProcessor, LoadTimeWeaverAwareProcessor, MethodValidationPostProcessor, PersistenceAnnotationBeanPostProcessor, PersistenceExceptionTranslationPostProcessor, ScheduledAnnotationBeanPostProcessor, ScriptFactoryPostProcessor, ServletContextAwareProcessor, SimpleServletPostProcessor
public interface BeanPostProcessor {/*** Apply this {@code BeanPostProcessor} to the given new bean instance <i>before</i> any bean* initialization callbacks (like InitializingBean's {@code afterPropertiesSet}* or a custom init-method). The bean will already be populated with property values.* The returned bean instance may be a wrapper around the original.* <p>The default implementation returns the given {@code bean} as-is.* @param bean the new bean instance* @param beanName the name of the bean* @return the bean instance to use, either the original or a wrapped one;* if {@code null}, no subsequent BeanPostProcessors will be invoked* @throws org.springframework.beans.BeansException in case of errors* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet*/@Nullabledefault Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {return bean;}/*** Apply this {@code BeanPostProcessor} to the given new bean instance <i>after</i> any bean* initialization callbacks (like InitializingBean's {@code afterPropertiesSet}* or a custom init-method). The bean will already be populated with property values.* The returned bean instance may be a wrapper around the original.* <p>In case of a FactoryBean, this callback will be invoked for both the FactoryBean* instance and the objects created by the FactoryBean (as of Spring 2.0). The* post-processor can decide whether to apply to either the FactoryBean or created* objects or both through corresponding {@code bean instanceof FactoryBean} checks.* <p>This callback will also be invoked after a short-circuiting triggered by a* {@link InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation} method,* in contrast to all other {@code BeanPostProcessor} callbacks.* <p>The default implementation returns the given {@code bean} as-is.* @param bean the new bean instance* @param beanName the name of the bean* @return the bean instance to use, either the original or a wrapped one;* if {@code null}, no subsequent BeanPostProcessors will be invoked* @throws org.springframework.beans.BeansException in case of errors* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet* @see org.springframework.beans.factory.FactoryBean*/@Nullabledefault Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {return bean;}}

DestructionAwareBeanPostProcessor

DestructionAwareBeanPostProcessor 是一个扩展自 BeanPostProcessor 的接口,用于在 Spring 容器销毁 bean 前执行自定义的销毁操作,并可以判断是否需要销毁该 bean。

// CommonAnnotationBeanPostProcessor, InitDestroyAnnotationBeanPostProcessor, PersistenceAnnotationBeanPostProcessor, ScheduledAnnotationBeanPostProcessor, SimpleServletPostProcessor
public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor {/*** Apply this BeanPostProcessor to the given bean instance before its* destruction, for example, invoking custom destruction callbacks.* <p>Like DisposableBean's {@code destroy} and a custom destroy method, this* callback will only apply to beans which the container fully manages the* lifecycle for. This is usually the case for singletons and scoped beans.* @param bean the bean instance to be destroyed* @param beanName the name of the bean* @throws org.springframework.beans.BeansException in case of errors* @see org.springframework.beans.factory.DisposableBean#destroy()* @see org.springframework.beans.factory.support.AbstractBeanDefinition#setDestroyMethodName(String)*/void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException;/*** Determine whether the given bean instance requires destruction by this* post-processor.* <p>The default implementation returns {@code true}. If a pre-5 implementation* of {@code DestructionAwareBeanPostProcessor} does not provide a concrete* implementation of this method, Spring silently assumes {@code true} as well.* @param bean the bean instance to check* @return {@code true} if {@link #postProcessBeforeDestruction} is supposed to* be called for this bean instance eventually, or {@code false} if not needed* @since 4.3*/default boolean requiresDestruction(Object bean) {return true;}}

InstantiationAwareBeanPostProcessor

InstantiationAwareBeanPostProcessor 是一个扩展自 BeanPostProcessor 的接口,用于在 Spring 容器实例化 bean 之前和之后进行自定义处理,允许修改 bean 实例化过程及其属性设置。

// AbstractAdvisingBeanPostProcessor, AbstractAdvisorAutoProxyCreator, AbstractAutoProxyCreator, AbstractBeanFactoryAwareAdvisingPostProcessor, AnnotationAwareAspectJAutoProxyCreator, AspectJAwareAdvisorAutoProxyCreator, AsyncAnnotationBeanPostProcessor, AutowiredAnnotationBeanPostProcessor, BeanNameAutoProxyCreator, CommonAnnotationBeanPostProcessor, DefaultAdvisorAutoProxyCreator, InfrastructureAdvisorAutoProxyCreator, MethodValidationPostProcessor, PersistenceAnnotationBeanPostProcessor, PersistenceExceptionTranslationPostProcessor, ScriptFactoryPostProcessor
public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {/*** Apply this BeanPostProcessor <i>before the target bean gets instantiated</i>.* The returned bean object may be a proxy to use instead of the target bean,* effectively suppressing default instantiation of the target bean.* <p>If a non-null object is returned by this method, the bean creation process* will be short-circuited. The only further processing applied is the* {@link #postProcessAfterInitialization} callback from the configured* {@link BeanPostProcessor BeanPostProcessors}.* <p>This callback will be applied to bean definitions with their bean class,* as well as to factory-method definitions in which case the returned bean type* will be passed in here.* <p>Post-processors may implement the extended* {@link SmartInstantiationAwareBeanPostProcessor} interface in order* to predict the type of the bean object that they are going to return here.* <p>The default implementation returns {@code null}.* @param beanClass the class of the bean to be instantiated* @param beanName the name of the bean* @return the bean object to expose instead of a default instance of the target bean,* or {@code null} to proceed with default instantiation* @throws org.springframework.beans.BeansException in case of errors* @see #postProcessAfterInstantiation* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass()* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName()*/@Nullabledefault Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {return null;}/*** Perform operations after the bean has been instantiated, via a constructor or factory method,* but before Spring property population (from explicit properties or autowiring) occurs.* <p>This is the ideal callback for performing custom field injection on the given bean* instance, right before Spring's autowiring kicks in.* <p>The default implementation returns {@code true}.* @param bean the bean instance created, with properties not having been set yet* @param beanName the name of the bean* @return {@code true} if properties should be set on the bean; {@code false}* if property population should be skipped. Normal implementations should return {@code true}.* Returning {@code false} will also prevent any subsequent InstantiationAwareBeanPostProcessor* instances being invoked on this bean instance.* @throws org.springframework.beans.BeansException in case of errors* @see #postProcessBeforeInstantiation*/default boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {return true;}/*** Post-process the given property values before the factory applies them* to the given bean.* <p>The default implementation returns the given {@code pvs} as-is.* @param pvs the property values that the factory is about to apply (never {@code null})* @param bean the bean instance created, but whose properties have not yet been set* @param beanName the name of the bean* @return the actual property values to apply to the given bean (can be the passed-in* PropertyValues instance), or {@code null} to skip property population* @throws org.springframework.beans.BeansException in case of errors* @since 5.1*/@Nullabledefault PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {return pvs;}}

MergedBeanDefinitionPostProcessor

MergedBeanDefinitionPostProcessor 是一个扩展自 BeanPostProcessor 的接口,用于在合并后的 bean 定义过程中进行自定义处理,并允许在 bean 定义重置时清理相关元数据。

// AutowiredAnnotationBeanPostProcessor, CommonAnnotationBeanPostProcessor, InitDestroyAnnotationBeanPostProcessor, JmsListenerAnnotationBeanPostProcessor, PersistenceAnnotationBeanPostProcessor, ScheduledAnnotationBeanPostProcessor
public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor {/*** Post-process the given merged bean definition for the specified bean.* @param beanDefinition the merged bean definition for the bean* @param beanType the actual type of the managed bean instance* @param beanName the name of the bean* @see AbstractAutowireCapableBeanFactory#applyMergedBeanDefinitionPostProcessors*/void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);/*** A notification that the bean definition for the specified name has been reset,* and that this post-processor should clear any metadata for the affected bean.* <p>The default implementation is empty.* @param beanName the name of the bean* @since 5.1* @see DefaultListableBeanFactory#resetBeanDefinition*/default void resetBeanDefinition(String beanName) {}}

SmartInstantiationAwareBeanPostProcessor

SmartInstantiationAwareBeanPostProcessor 扩展了 InstantiationAwareBeanPostProcessor,提供了一些额外的回调方法,用于预测、确定和操作 bean 类型、构造函数以及早期访问的引用,支持更细粒度的 bean 创建和初始化控制。

// AbstractAdvisingBeanPostProcessor, AbstractAdvisorAutoProxyCreator, AbstractAutoProxyCreator, AbstractBeanFactoryAwareAdvisingPostProcessor, AnnotationAwareAspectJAutoProxyCreator, AspectJAwareAdvisorAutoProxyCreator, AsyncAnnotationBeanPostProcessor, AutowiredAnnotationBeanPostProcessor, BeanNameAutoProxyCreator, DefaultAdvisorAutoProxyCreator, InfrastructureAdvisorAutoProxyCreator, MethodValidationPostProcessor, PersistenceExceptionTranslationPostProcessor, ScriptFactoryPostProcessor
public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessor {/*** Predict the type of the bean to be eventually returned from this* processor's {@link #postProcessBeforeInstantiation} callback.* <p>The default implementation returns {@code null}.* Specific implementations should try to predict the bean type as* far as known/cached already, without extra processing steps.* @param beanClass the raw class of the bean* @param beanName the name of the bean* @return the type of the bean, or {@code null} if not predictable* @throws org.springframework.beans.BeansException in case of errors*/@Nullabledefault Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {return null;}/*** Determine the type of the bean to be eventually returned from this* processor's {@link #postProcessBeforeInstantiation} callback.* <p>The default implementation returns the given bean class as-is.* Specific implementations should fully evaluate their processing steps* in order to create/initialize a potential proxy class upfront.* @param beanClass the raw class of the bean* @param beanName the name of the bean* @return the type of the bean (never {@code null})* @throws org.springframework.beans.BeansException in case of errors* @since 6.0*/default Class<?> determineBeanType(Class<?> beanClass, String beanName) throws BeansException {return beanClass;}/*** Determine the candidate constructors to use for the given bean.* <p>The default implementation returns {@code null}.* @param beanClass the raw class of the bean (never {@code null})* @param beanName the name of the bean* @return the candidate constructors, or {@code null} if none specified* @throws org.springframework.beans.BeansException in case of errors*/@Nullabledefault Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {return null;}/*** Obtain a reference for early access to the specified bean,* typically for the purpose of resolving a circular reference.* <p>This callback gives post-processors a chance to expose a wrapper* early - that is, before the target bean instance is fully initialized.* The exposed object should be equivalent to what* {@link #postProcessBeforeInitialization} / {@link #postProcessAfterInitialization}* would expose otherwise. Note that the object returned by this method will* be used as the bean reference unless the post-processor returns a different* wrapper from said post-process callbacks. In other words, those post-process* callbacks may either eventually expose the same reference or alternatively* return the raw bean instance from those subsequent callbacks (if the wrapper* for the affected bean has been built for a call to this method already,* it will be exposed as the final bean reference by default).* <p>The default implementation returns the given {@code bean} as-is.* @param bean the raw bean instance* @param beanName the name of the bean* @return the object to expose as the bean reference* (typically the passed-in bean instance as default)* @throws org.springframework.beans.BeansException in case of errors*/default Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {return bean;}}
实现类用途
AbstractAdvisingBeanPostProcessor用于 Spring AOP,提供通用的 Bean 后处理逻辑,支持自动代理和通知增强。
AbstractAdvisorAutoProxyCreator创建代理 Bean,并为其应用切面通知,用于自动代理。
AbstractAutoProxyCreator用于创建自动代理,增强 Bean。
AbstractBeanFactoryAwareAdvisingPostProcessor支持增强 Bean 的功能,并能在 Bean Factory 中获得访问。
AdvisorAdapterRegistrationManager用于注册和管理 Spring AOP 中的 Advisor。
AnnotationAwareAspectJAutoProxyCreator结合 AspectJ 注解为 Bean 自动创建代理。
AspectJAwareAdvisorAutoProxyCreator专门为 Spring AOP 创建基于 AspectJ 的代理。
AsyncAnnotationBeanPostProcessor用于处理 @Async 注解,将异步任务执行功能应用到 Bean 中。
AutowiredAnnotationBeanPostProcessor处理 @Autowired 注解,自动注入依赖的 Bean。
BeanNameAutoProxyCreator通过 Bean 名称创建代理 Bean,适用于特定名称的 Bean。
BeanValidationPostProcessor自动触发 Bean 的验证,适用于 @Valid 注解的验证。
CommonAnnotationBeanPostProcessor处理 Java EE 注解(如 @PostConstruct, @PreDestroy)的后处理。
DefaultAdvisorAutoProxyCreator默认的自动代理创建器,处理 AOP 中的 Advisor。
ImportAwareAotBeanPostProcessor用于处理 AOT(Ahead-of-Time)期间的导入依赖。
InfrastructureAdvisorAutoProxyCreator创建基础设施相关的 Advisor 自动代理,通常用于系统级的 AOP 配置。
InitDestroyAnnotationBeanPostProcessor处理 @PostConstruct@PreDestroy 注解的 Bean 后处理器。
JmsListenerAnnotationBeanPostProcessor处理 @JmsListener 注解,将方法绑定为 JMS 消息监听器。
LoadTimeWeaverAwareProcessor处理类加载时间增强,通常与字节码增强技术(如 AspectJ)配合使用。
MethodValidationPostProcessor用于处理方法级验证的 Bean 后处理器。
PersistenceAnnotationBeanPostProcessor处理持久化相关注解(如 @Transactional),自动配置事务管理。
PersistenceExceptionTranslationPostProcessor处理持久化异常的翻译,将数据库异常转换为 Spring 的数据访问异常。
ScheduledAnnotationBeanPostProcessor处理 @Scheduled 注解,自动配置定时任务。
ScriptFactoryPostProcessor处理脚本相关的配置,通常用于与脚本引擎相关的 Bean 配置。
ServletContextAwareProcessor使 Bean 能访问 ServletContext,用于 Web 环境的上下文访问。
SimpleServletPostProcessor简单的 Servlet 后处理器,用于处理 Servlet 配置。

SmartInitializingSingleton

SmartInitializingSingleton 接口提供了一个 afterSingletonsInstantiated 方法,该方法在所有普通单例 bean 实例化完成后被调用,适用于在容器启动过程中需要确保所有单例已创建的场景。

public interface SmartInitializingSingleton {/*** Invoked right at the end of the singleton pre-instantiation phase,* with a guarantee that all regular singleton beans have been created* already. {@link ListableBeanFactory#getBeansOfType} calls within* this method won't trigger accidental side effects during bootstrap.* <p><b>NOTE:</b> This callback won't be triggered for singleton beans* lazily initialized on demand after {@link BeanFactory} bootstrap,* and not for any other bean scope either. Carefully use it for beans* with the intended bootstrap semantics only.*/void afterSingletonsInstantiated();}

InitializingBean

InitializingBean 接口提供了一个 afterPropertiesSet 方法,在所有 bean 属性设置完成后由容器调用,允许 bean 进行验证和最终初始化。

public interface InitializingBean {/*** Invoked by the containing {@code BeanFactory} after it has set all bean properties* and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc.* <p>This method allows the bean instance to perform validation of its overall* configuration and final initialization when all bean properties have been set.* @throws Exception in the event of misconfiguration (such as failure to set an* essential property) or if initialization fails for any other reason*/void afterPropertiesSet() throws Exception;}

DisposableBean

DisposableBean 接口提供了一个 destroy 方法,在容器销毁 bean 时调用,允许 bean 释放资源并进行清理。

public interface DisposableBean {/*** Invoked by the containing {@code BeanFactory} on destruction of a bean.* @throws Exception in case of shutdown errors. Exceptions will get logged* but not rethrown to allow other beans to release their resources as well.*/void destroy() throws Exception;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/89460.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/89460.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MISRA C-2012准则之声明与定义

目录 一、MISRA C简介 二、声明与定义 1. 必需。类型应被显式声明。 2. 必需。函数应以原型形式命名参数。 3. 必需。所有对象和函数的声明需要使用完全相同的名字和参数。 4. 必需。当定义有外部链接的对象或函数时&#xff0c;兼容声明应是可见的。 5. 必需。外部变量…

【blender】使用Vscode进行blender调试

配置vscodeblender 直接使用blender中的text editor没有代码补全&#xff0c;终端输出通常和blender不在同一个页面&#xff0c;只适合非常简单的代码测试。使用Vscode能有效提高blender调试的效率&#xff0c;具体方式见&#xff1a;VSCode 开发 Blender脚本工具配置。 调试…

Au速成班-乐理知识补充+网页下载音乐

音质分类 通过查看音频频谱&#xff0c;128Kbps、192Kbps、320Kbps、无损&#xff08;Lossless HD&#xff09;CD音质&#xff08;频率都在20kHz以上&#xff09;。 各家平台对无损的定义不一样&#xff0c;em各有说法吧。 无损的含义是&#xff1a;无损失的声音格式。只要能…

JAVA中的Collection集合及ArrayList,LinkedLIst,HashSet,TreeSet和其它实现类的常用方法

文章目录前言一、Collection 接口常用方法1.boolean add(E e)2.boolean remove(Object o)3.boolean contains(Object o)4.boolean isEmpty()5.int size()6.void clear()7.Object[] toArray()8.boolean containsAll(Collection<?> c)9.boolean addAll(Collection<? e…

有n棍棍子,棍子i的长度为ai,想要从中选出3根棍子组成周长尽可能长的三角形。请输出最大的周长,若无法组成三角形则输出0。

题目描述&#xff1a; 有n棍棍子&#xff0c;棍子i的长度为ai&#xff0c;想要从中选出3根棍子组成周长尽可能长的三角形。请输出最大的周长&#xff0c;若无法组成三角形则输出0。 算法为O(nlogn) 初始理解题目 首先&#xff0c;我们需要清楚地理解题目要求&#xff1a; 输入…

【Echarts】 电影票房汇总实时数据横向柱状图比图

效果图code <!DOCTYPE html> <html> <head><meta charset"utf-8"><title>圆角柱状图</title><script src"https://cdn.jsdelivr.net/npm/echarts5.4.3/dist/echarts.min.js"></script> </head> <…

【深度学习基础】PyTorch中model.eval()与with torch.no_grad()以及detach的区别与联系?

目录1. 核心功能对比2. 使用场景对比3. 区别与联系4. 典型代码示例(1) 模型评估阶段(2) GAN 训练中的判别器更新(3) 提取中间特征5. 关键区别总结6. 常见问题与解决方案(1) 问题&#xff1a;推理阶段显存爆掉(2) 问题&#xff1a;Dropout/BatchNorm 行为异常(3) 问题&#xff1…

博客摘录「 华为云平台-FusionSphere OpenStack 8.2.1 系统加固」2025年7月15日

编号 加固项 "风险 等级" 加固原理/Rationale 审计方法/Audit 期望结果/Expect Results 加固方法/Remediation 1 OpenSSH加固配置 1.1 OpenSSH加固配置 1.1.1 SSH使用的版本 H "Op…

永磁同步电机MTPA与MTPV曲线具体仿真实现

永磁同步电机MTPA与MTPV曲线具体仿真实现 近期做了一些标定试验&#xff0c;实际电机参数并不是确定的&#xff0c;而是变化的&#xff0c;因此很难通过解析的方法算出MTPA的对应点&#xff0c;以及在弱磁区如何过度到MTPV。这个在实际情况下都是一点点标出来的&#xff0c;我这…

Adobe Acrobat 插件功能、应用与开发

什么是 Acrobat 插件&#xff1f; Adobe Acrobat 插件是一种能够扩展 Adobe Acrobat 阅读器/查看器功能的软件组件。Acrobat 是用于查看、创建和编辑 PDF 文档的流行程序&#xff0c;而插件可以为其添加新功能&#xff0c;例如&#xff1a; #mermaid-svg-iqdM1wLkFQhd3ilQ {fon…

Redis学习系列之——高并发应用的缓存问题(二)

一、布隆过滤器布隆过滤器由一个 BitMap 和若干 Hash 函数组成&#xff0c;可以用来快速判断一个值是否存在后端存储中。它是解决 Redis 缓存穿透问题的一个不错的解决方案。工作原理步骤1&#xff1a;当 key-value 键值对存储到 Redis 后&#xff0c;向布隆过滤器添加 key步骤…

Expression 类的静态方法

public static MethodCallExpression Call(Type type, // 包含目标方法的类型string methodName, // 方法名称Type[]? typeArguments, // 泛型方法的类型参数&#xff08;非泛型方法为 null&#xff09;params Expression[]? arguments // 方…

[Nagios Core] 事件调度 | 检查执行 | 插件与进程

第五章&#xff1a;事件调度 欢迎回到Nagios Core&#xff01; 在上一章第四章&#xff1a;配置加载中&#xff0c;我们了解了Nagios如何读取配置文件以知晓需要监控的对象&#xff0c;比如我们的朋友"Web Server 1"。此时Nagios内存中已构建完整的基础设施拓扑图。…

Web3 常用前端库介绍

一、Web3 前端开发&#xff1a;连接用户与区块链的桥梁 随着 Web3 生态的蓬勃发展&#xff0c;前端开发从传统的页面渲染进化为区块链交互的核心枢纽。Web3 前端库作为连接用户与区块链的桥梁&#xff0c;承担着钱包集成、合约交互、数据可视化等关键功能。本文将系统解析主流 …

cnpm命令报internal/modules/cjs/loader.js:797 throw err; ^ Error: Cannot find

在运行一个项目的时候&#xff0c;需要升级电脑各组件的版本&#xff0c;结果导致cnpm命令无法正常使用&#xff0c;cnpm任何命令都会报如下这个错&#xff1a;找了半天&#xff0c;发现是由于cnpm与npm的版本不一致导致的&#xff0c;所以需要卸载并重新安装cnpm&#xff0c;重…

15、鸿蒙Harmony Next开发:创建自定义组件

目录 自定义组件的基本用法 自定义组件的基本结构 struct Component freezeWhenInactive build()函数 Entry EntryOptions Reusable 成员函数/变量 自定义组件的参数规定 build()函数 自定义组件生命周期 自定义组件的创建和渲染流程 自定义组件重新渲染 自定义…

深入理解Map.Entry.comparingByValue()和Map.Entry.comparingByKey()

文章目录深入理解Map.Entry.comparingByValue()和Map.Entry.comparingByKey()1. 方法定义comparingByKey()comparingByValue()2. 基本用法2.1 使用comparingByKey()2.2 使用comparingByValue()3. 方法重载版本comparingByKey(Comparator)comparingByValue(Comparator)4. 高级用…

Mac下载mysql

安装 brew list --versions | grep mysql查看已安装的mysql版本brew search mysql查看支持的mysql版本brew info mysql查看mysql版本信息brew install mysql进行安装/opt/homebrew/opt/mysql/bin/mysqld --initialize-insecure --user$(whoami) --basedir$(brew --prefix mysql…

PageHelper使用说明文档

文章目录一、简介二、集成步骤三、使用方法四、注意事项五、高级用法一、简介 PageHelper 是一个开源的 MyBatis 分页插件&#xff0c;它可以帮助我们在使用 MyBatis 进行数据库操作时方便地实现分页功能。通过简单的配置和少量的代码修改&#xff0c;就可以在查询数据时实现分…

grpo nl2sql qwen3 模型强化学习训练有效果的成立条件有哪些

在使用GRPO&#xff08;强化学习算法&#xff09;对Qwen3模型在NL2SQL&#xff08;自然语言到SQL转换&#xff09;任务上进行强化学习&#xff08;RL&#xff09;训练时&#xff0c;其效果成立的核心条件可归纳为以下几个关键维度&#xff0c;这些条件相互关联&#xff0c;共同…