在 Solon 提倡“克制”的原则下,托管组件分为:

  • 普通组件:

    • 主要由内核提供的:@Configuration、@Component、@Controller、@Remoting 注解的类
    • 其中 @Controller、@Remoting 支持函数拦截
  • 代理组件:
    • 主要由内核提供的:@ProxyComponent(需要 solon.proxy 插件提供支持)注解的类
    • 支持函数可拦截

1、区别

@ProxyComponent

  • 被代理(即类的外面又包了一层类,看不见的),支持函数可拦截。例如支持:@Tran、@Cache 等借助函数拦截实现的能力

支持函数可拦截:

@ProxyComponent
public class UserService{
@Tran
public void addUser(User user){ }
}

@Component

  • 不支持函数可拦截
  • 支持特定形态自动处理
  • 支持函数提取
  • 支持 Bean、BeanWrap 订阅

支持特定形态自动处理:LifecycleBean、EventListener、Filter、RouterInterceptor、Handler、LoadBalance.Factory。例:EventListener 会自动注册 EventBus

@Component
public class DemoEventListener implements EventListener<DemoEvent>{
@Override
public void onEvent(DemoEvent event) throws Throwable{ }
}

支持函数被提取:通过 aopContext.beanExtractorAdd(Scheduled.class, new ScheduledExtractor()) 直接提取组件的 @Scheduled 函数

@Component
public class DemoJob{
@Scheduled
public void job1() throws Throwable{ }
}

支持Bean、BeanWrap 订阅:(订阅,也支持 @Configuration + @Bean 产生的)

//通过订阅获取多个 IXxx 实现的组件或Bean(要在容器扫描前,提前订阅)
aopContext.subBeansOfType(IXxx.class, bean->{ }); @Component
public class DemoBean1 implements IXxx{ } @Component
public class DemoBean2 implements IXxx{ }

2、了解代理与拦截

Solon2 常用注解之 @Component 与 @ProxyComponent 的区别的更多相关文章

  1. [刘阳Java]_Spring常用注解介绍_第6讲

    Spring的注解是在Spring2.5的版本中引入的,目的简化XML配置.在企业开发过程中使用注解的频率非常高,但是学习注解的前提是大家一定要对Spring基于XML配置要熟悉,这是我个人建议,因为 ...

  2. SpringMVC常用注解@Controller,@Service,@repository,@Component

    SpringMVC常用注解@Controller,@Service,@repository,@Component controller层使用@controller注解 @Controller 用于标记 ...

  3. Spring 和 SpringMVC 常用注解和配置(@Autowired、@Resource、@Component、@Repository、@Service、@Controller的区别)

    Spring 常用注解 总结内容 一.Spring部分 1.声明bean的注解 2.注入bean的注解 3.java配置类相关注解 4.切面(AOP)相关注解 5.事务注解 6.@Bean的属性支持 ...

  4. Spring系列之Spring常用注解总结

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  5. Spring常用注解汇总

    本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component- ...

  6. Spring常用注解,自动扫描装配Bean

    1 引入context命名空间(在Spring的配置文件中),配置文件如下: xmlns:context="http://www.springframework.org/schema/con ...

  7. Spring常用注解介绍【经典总结】

    Spring的一个核心功能是IOC,就是将Bean初始化加载到容器中,Bean是如何加载到容器的,可以使用Spring注解方式或者Spring XML配置方式. Spring注解方式减少了配置文件内容 ...

  8. 一 : springmvc常用注解

    springmvc常用注解详解1.@Controller在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层 ...

  9. Spring Boot常用注解总结

    Spring Boot常用注解总结 @RestController和@RequestMapping注解 @RestController注解,它继承自@Controller注解.4.0之前的版本,Spr ...

  10. SpringBoot | 第六章:常用注解介绍及简单使用

    前言 之前几个章节,大部分都是算介绍springboot的一些外围配置,比如日志配置等.这章节开始,开始总结一些关于springboot的综合开发的知识点.由于SpringBoot本身是基于Sprin ...

随机推荐

  1. 【第4次作业】CNN实战

    使用VGG模型进行猫狗大战 import numpy as np import matplotlib.pyplot as plt import os import torch import torch ...

  2. 20193314白晨阳《Python程序设计》实验四 Python综合实践

    课程:<Python程序设计> 班级: 1933 姓名: 白晨阳 学号:20193314 实验教师:王志强老师 实验日期:2021年6月13日 必修/选修: 公选课 实验内容: Pytho ...

  3. win10系统格式化后进行虚拟分区

    1. 目的 目前win10磁盘分区多数人采用两种方式: 1:只分一个C盘,文件在C盘以目录区分. 缺点:所有文件都在一起,区分查找比较麻烦. 2:物理分区,分多个盘,如C,D,E等等 缺点:容量固定, ...

  4. 钉钉扫码登录第三方,appSecret签名算法(附包名)

    包名 import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import javax.crypto.Mac; ...

  5. NOIP2011普及组

    T2  统计单词数 也是一道经典题 字符串匹配 #include<iostream> #include<cstdio> #include<map> #include ...

  6. python Queue(队列学习)

    Python 的Queue模块中提供了同步的.线程安全的队列类,包括FIFO(先入先出)队列Queue,LIFO(后入先出)队列LifoQueue,和优先级队列PriorityQueue.这些队列都实 ...

  7. 【原创】2022年linux环境下QT6不支持中文输入法解决方案

    1.配置环境 export PATH="~/目录/Qt/6.x.x/gcc_64/bin":$PATH export PATH="~/目录/Qt/Tools/Cmake/ ...

  8. 线程Thread小记

    1 public class ConcurentDemo extends Thread { 2 @Override 3 public void run() { 4 super.run(); 5 Sys ...

  9. Static详细讲解

    Static详细讲解 package com.andy.base.oop.demo01.demo07; import sun.dc.path.PathError; public class Perso ...

  10. DSC:数仓SQL脚本迁移的神奇工具

    摘要:本文介绍的DSC工具是针对数据库切换时面临的迁移任务而开发的免安装命令行工具.目的是提供简单.快速.可靠的SQL脚本迁移服务. 本文分享自华为云社区<GaussDB(DWS)DSC工具系列 ...