首页 > 其他分享 >1.24总结

1.24总结

时间:2024-01-24 19:58:50浏览次数:28  
标签:总结 springframework item context org var import 1.24

package com.mediator;

import com.mediator.Annotations.CommandHandler;
import com.mediator.Annotations.EnableCommandHandler;
import com.mediator.Annotations.PipeLine;
import com.mediator.Mediator.IMediator;
import com.mediator.Mediator.impl.Mediator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.*;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.type.filter.AnnotationTypeFilter;

import java.util.Set;

@Configuration
public class MediatorConfiguration {

@Autowired
private ApplicationContext context;
public MediatorConfiguration()
{

}
@Bean
public IMediator InjectMediator()
{
    var enable=context.getBeansWithAnnotation(EnableCommandHandler.class);
    if (!enable.isEmpty())
    {
        var application=enable.values().iterator().next();
        EnableCommandHandler handler = AnnotationUtils.findAnnotation(application.getClass(), EnableCommandHandler.class);
        if (handler!=null)
        {
            var path=handler.path();
            if (!path.isEmpty())
            {ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) context;
                DefaultListableBeanFactory factory=(DefaultListableBeanFactory)configurableApplicationContext.getBeanFactory();
                var allCommandClass=scanCommandHandlerClasses(path);
                if (!allCommandClass.isEmpty())
                {
                    for(BeanDefinition item:allCommandClass)
                    {
                        var name=item.getBeanClassName();
                        item.setScope("request");
                        factory.registerBeanDefinition(name,item);
                    }
                }
                var pipeClass=scanPipeLineClasses(path);
                if (!pipeClass.isEmpty())
                {
                    for(BeanDefinition item:pipeClass)
                    {
                        var name=item.getBeanClassName();
                        item.setScope("request");
                        factory.registerBeanDefinition(name,item);
                    }
                }
            }
        }
    }
    return new Mediator();
}
private   Set<BeanDefinition> scanCommandHandlerClasses(String basePackage) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    ClassPathBeanDefinitionScanner scanner =
            new ClassPathBeanDefinitionScanner(context,true);
    // 添加过滤条件,只扫描带有 @CommandHandler 注解的类
    scanner.addIncludeFilter(new AnnotationTypeFilter(CommandHandler.class));
    // 扫描指定包路径
    Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage);
    return candidates;
}
private   Set<BeanDefinition> scanPipeLineClasses(String basePackage) {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    ClassPathBeanDefinitionScanner scanner =
            new ClassPathBeanDefinitionScanner(context,true);
    // 添加过滤条件,只扫描带有 @PipeLine 注解的类
    scanner.addIncludeFilter(new AnnotationTypeFilter(PipeLine.class));
    // 扫描指定包路径
    Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage);
    return candidates;
}

}

标签:总结,springframework,item,context,org,var,import,1.24
From: https://www.cnblogs.com/XiMenXve/p/17985729

相关文章

  • petalinux 报错总结
    Failedtomenuconfigprojectcomponent....解决办法此处是由于Terminal(终端)的界面太窄导致的,把Terminal(终端)界面拉宽即可;重新执行命令【petalinux-config--get-hw-description=*.xsa“path”】后,可以看到配置界面弹出来了,且没有了刚刚的错误。do_rootfs:Thepostinstall......
  • 1.24学习进度
    1.RDD的创建通过并行化集合创建(本地对象转分布式RDD)读取外部数据源(读取文件):textfileapi(可以读取本地数据)2.算子是什么算子:分布式集合对象上的api方法/函数:本地对象的api3.算子的分类   Transformation:转换算子(返回值是rdd)特性:这类算子时lazy、懒加载的,如果没有action算子......
  • 每日总结2024年1月24日
    比较适合用来做图表的网站首页-MadeAPiealova是一个轻量级的请求策略库,支持开发者使用声明式实现例如请求共享、分页请求、表单提交、断点续传等各种较复杂的请求,让开发者使用非常少量的代码就可以实现高可用性和高流畅性的请求功能,这意味着,你再也不需要自己绞尽脑汁编写请......
  • 1.23总结
    packagemainimport("fmt""os")funcmain(){commandArgs:=os.Argsfmt.Println(commandArgs)}执行程序:递归浏览指定目录下所有文件gorunmain.go--namels--value/etc-r输出:[/tmp/go-build2637413899/b001/exe/main--namels--value/etc-r]命令行参数......
  • 2023 的一些总结
    2023的一些总结李宗盛在山丘开头里面写道,"想说却还没说的还很多攒着是因为想写成歌"。同样的,在印象中在2023好像做了很多东西,接触了很多技术,但是一直没有整理,攒着攒着就到年底了。细细思考了一下,有两个板块是今年主要发力的点对网络的探索对业务代码优化的思考对网络......
  • 今日总结
    统计男女人数,并分别计算出男性和女性的最高和最低身高,数据格式“序号M/F身高” //生成性别身高数据,格式“序号性别(M/F)身高”privatestaticvoidmakeHeightData()throwsIOException{FilenewFile=newFile("src/main/files/heightData.txt");......
  • 项目总结
    时间片轮询:结构体封装每个任务的时间片(也就是执行间隔),计数器,函数指针。采用定时器计时。比如说任务1每2s执行一次,任务2每5s执行一次,定时器每1s产生中断,定时时间一到每个任务的计数器就加1,当计数器和时间片相等时执行该任务。任务冲突:将每个任务对应的结构体装入结构体数组,采用遍......
  • 2024.01 总结
    1.模拟赛总的来说状态较好,只有一次较大的挂分。1-1.优点:思维方面:能够推出DP式子,通过打表找到一些规律。码力方面:基础的数据结构实现很少出错。策略方面:先把自己能拿的分拿满。1-2.缺点:思维方面:推出式子不会优化。码力方面:难以实现复杂的数据结构和代码。......
  • 每日总结(python文本分析)
    导入文本文档并输出在终端#Python3.x版本importos#获取根目录下文件的绝对路径root_path="./"file_path=os.path.join(root_path,'pinglun.txt')try:#打开文本文件并读取所有内容withopen(file_path,'r',encoding='utf-8')asfile:......
  • 高效又稳定的ChatGPT大模型训练技巧总结,让训练事半功倍!
    高效又稳定的ChatGPT大模型训练技巧总结,让训练事半功倍!前言近期,ChatGPT成为了全网热议的话题。ChatGPT是一种基于大规模语言模型技术(LLM,largelanguagemodel)实现的人机对话工具。现在主流的大规模语言模型都采用Transformer网络,通过极大规模的数据进行自监督训练。但是,......