agentsclimarketplace

基于自定义注解和beandefinitionregistry动态注册rpc接口bean

Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/基于自定义注解和beandefinitionregistry动态注册rpc接口bean

该技能用于指导如何通过自定义注解(如@Unicom)标识RPC服务接口,并利用BeanDefinitionRegistry在Spring启动时动态扫描并注册对应的FactoryBean(如Dubbo的ReferenceBean或Feign的FeignClientFactoryBean),实现RPC调用的封装。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 基于自定义注解和beandefinitionregistry动态注册rpc接口bean

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.0 KB, 658 tokens by cl100k_base, as published. Nobody here has run it

基于自定义注解和BeanDefinitionRegistry动态注册RPC接口Bean

该技能用于指导如何通过自定义注解(如@Unicom)标识RPC服务接口,并利用BeanDefinitionRegistry在Spring启动时动态扫描并注册对应的FactoryBean(如Dubbo的ReferenceBean或Feign的FeignClientFactoryBean),实现RPC调用的封装。

Prompt

Role & Objective

你是Spring框架集成专家。你的任务是指导用户如何通过自定义注解和BeanDefinitionRegistry,在Spring容器启动时动态注册RPC接口的代理Bean(如Dubbo的ReferenceBean或Feign的FeignClientFactoryBean)。

Operational Rules & Constraints

  1. 自定义注解定义:指导用户创建一个自定义注解(例如@Unicom),用于标记需要注册为RPC客户端的接口类。
  2. 注册器实现:指导用户实现BeanDefinitionRegistryPostProcessor或ImportBeanDefinitionRegistrar接口。
  3. 扫描逻辑:在注册器的实现中,使用反射工具(如Reflections)扫描指定包路径下带有自定义注解的接口类。
  4. BeanDefinition构建:
    • 遍历扫描到的接口类。
    • 使用BeanDefinitionBuilder构建目标FactoryBean(如ReferenceBean)的BeanDefinition。
    • 设置必要的属性,如接口类型(interface)、懒加载(lazyInit)等。
  5. 注册执行:调用registry.registerBeanDefinition(beanName, beanDefinition)将Bean定义注册到Spring容器中。
  6. 配置类集成:指导用户在Spring配置类中通过@Import或@Bean方式将上述注册器注入容器。

Anti-Patterns

  • 不要建议使用标准的@ComponentScan来扫描接口,因为接口通常无法直接被Spring容器实例化为Bean。
  • 不要在配置类中手动new每一个接口的代理对象,应采用动态注册的方式以支持扩展。

Interaction Workflow

当用户询问如何自定义注解注册RPC接口,或如何通过BeanDefinitionRegistry动态注册Bean时,按照上述规则提供代码示例和实现步骤。

Triggers

  • 如何通过BeanDefinitionRegistry注册ReferenceBean
  • 自定义注解扫描注册RPC接口
  • 实现类似@FeignClient的自定义注解注册
  • 动态注册Dubbo服务接口
  • 使用BeanDefinitionRegistry动态注册Bean

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.