登录
/
注册
首页
论坛
其它
首页
科技
业界
安全
程序
广播
Follow
关于
博客
发1篇日志+1圆
记录
发1条记录+2圆币
发帖说明
登录
/
注册
账号
自动登录
找回密码
密码
登录
立即注册
搜索
搜索
关闭
CSDN热搜
程序园
精品问答
技术交流
资源下载
本版
帖子
用户
软件
问答
教程
代码
VIP网盘
VIP申请
网盘
联系我们
道具
勋章
任务
设置
我的收藏
退出
腾讯QQ
微信登录
返回列表
首页
›
业界区
›
业界
›
Spring AOP 与 Solon AOP 有什么区别?
Spring AOP 与 Solon AOP 有什么区别?
[ 复制链接 ]
啤愿
2025-8-23 11:26:30
Spring 和 Solon 作为容器型框架。都具有 IOC 和 AOP 的能力。其中:
Spring AOP 使用表达式确定“切入点”,可以是某个注解(有侵入),可以是包名或类名或方法(无侵入)
Solon AOP 只使用某个注解确定“切入点”(有侵入)
先看两个示例
1、Spring AOP 示例
Spring AOP 有很多不同的能力构建方式。此处采用更简洁的一种方式:
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class LoggingAspect {
@Pointcut("execution(* com.example.demo.service.*.*(..))") //也可以是某注解表达式
public void serviceLayer() {}
@Around("serviceLayer()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("test");
return joinPoint.proceed();
}
}
复制代码
应用示例
package com.example.demo.service;
@Component
public class UserService {
public String getUserById(Long id) {
return "user-" + id;
}
public void updateUser(String user) {
System.out.println("update: " + user);
}
}
复制代码
2、Solon AOP 示例
Solon AOP 有两种能力构建方式。此处采用更简洁的一种方式:
import org.noear.solon.annotation.Around;
import org.noear.solon.core.aspect.Invocation;
import org.noear.solon.core.aspect.MethodInterceptor;
@Around(Logging.LoggingInterceptor.class) //为注解,附加包围处理的能力
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Logging {
class LoggingInterceptor implements MethodInterceptor {
@Override
public Object doIntercept(Invocation i) throws Throwable {
System.out.println("test");
return i.invoke();
}
}
}
复制代码
应用示例
package com.example.demo.service;
@Logging
@Component
public class UserService {
public String getUserById(Long id) {
return "user-" + id;
}
public void updateUser(String user) {
System.out.println("update: " + user);
}
}
复制代码
3、总结
体验感受Spring AOPSolon AOP有侵入体验通过表达式描述,使用时添加“注解”定义注解,使用时添加“注解”无侵入体验通过表达式描述包名或类名或方法,使用时无感/优点可以完全“无侵入”实现 AOP附加了什么能力比较透明缺点表达式有点难写;(可无限制添加)可能会有些混乱(不能随意添加)可能会有局限性
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
AOP
Spring
Solon
什么
区别
相关帖子
Solon StateMachine 实现状态机使用示例详解
Spring 调试新姿势:一眼看清运行时,用 Spring Debugger 少踩 90% 坑
linux系统目录和文件夹的区别
Spring @Component 和 @Bean 的区别与最佳实践
10分钟带你体验 Solon 的状态机
startActivity到底发生了什么(二)
【URP】什么是[深度偏移](Slope Scale Depth Bias)
使用Spring Boot对接印度股票市场API开发实践
做俯卧撑有什么好处
回复
使用道具
举报
提升卡
置顶卡
沉默卡
喧嚣卡
变色卡
千斤顶
照妖镜
相关推荐
业界
Solon StateMachine 实现状态机使用示例详解
0
639
葛雅隽
2025-08-24
业界
Spring 调试新姿势:一眼看清运行时,用 Spring Debugger 少踩 90% 坑
0
908
申倩语
2025-08-24
安全
linux系统目录和文件夹的区别
0
924
颖顿庐
2025-08-28
业界
Spring @Component 和 @Bean 的区别与最佳实践
0
1029
剧拧并
2025-08-29
业界
10分钟带你体验 Solon 的状态机
0
491
欤夤
2025-08-29
安全
startActivity到底发生了什么(二)
0
391
盗衍
2025-08-30
业界
【URP】什么是[深度偏移](Slope Scale Depth Bias)
0
1025
圣罩
2025-08-31
安全
使用Spring Boot对接印度股票市场API开发实践
0
343
俏襟选
2025-09-01
问答
做俯卧撑有什么好处
0
8
新程序
2025-09-03
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
回复
本版积分规则
回帖并转播
回帖后跳转到最后一页
浏览过的版块
安全
签约作者
程序园优秀签约作者
发帖
啤愿
2025-8-23 11:26:30
关注
0
粉丝关注
16
主题发布
板块介绍填写区域,请于后台编辑
财富榜{圆}
敖可
9984
黎瑞芝
9990
杭环
9988
4
凶契帽
9988
5
氛疵
9988
6
虽裘侪
9986
7
猷咎
9986
8
接快背
9986
9
里豳朝
9986
10
肿圬后
9986
查看更多