Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项羽过江东
spring-framework-source
提交
ec92d71d
spring-framework-source
项目概览
项羽过江东
/
spring-framework-source
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
spring-framework-source
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ec92d71d
编写于
9月 03, 2023
作者:
项羽过江东
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aop 代码编译成功,添加了一个 demo 程序
上级
f06b35e2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
9 deletion
+40
-9
_03-aop-demo/src/main/java/com/matrix/nickel/AopApplication.java
...-demo/src/main/java/com/matrix/nickel/AopApplication.java
+1
-0
_03-aop-demo/src/main/java/com/matrix/nickel/aop/LogAspect.java
...p-demo/src/main/java/com/matrix/nickel/aop/LogAspect.java
+23
-8
_03-aop-demo/src/main/resources/log4j2.xml
_03-aop-demo/src/main/resources/log4j2.xml
+5
-1
docs/idea中spring项目的构建运行.md
docs/idea中spring项目的构建运行.md
+11
-0
images/配置facets开启AspectJ的编译.png
images/配置facets开启AspectJ的编译.png
+0
-0
未找到文件。
_03-aop-demo/src/main/java/com/matrix/nickel/AopApplication.java
浏览文件 @
ec92d71d
...
@@ -19,6 +19,7 @@ public class AopApplication {
...
@@ -19,6 +19,7 @@ public class AopApplication {
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
HelloConfigOfAOP
.
class
);
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
(
HelloConfigOfAOP
.
class
);
MathCalculator
mathCalculator
=
ctx
.
getBean
(
MathCalculator
.
class
);
MathCalculator
mathCalculator
=
ctx
.
getBean
(
MathCalculator
.
class
);
int
divide
=
mathCalculator
.
divide
(
4
,
1
);
int
divide
=
mathCalculator
.
divide
(
4
,
1
);
log
.
error
(
"ee"
,
new
RuntimeException
(
"e"
));
log
.
info
(
"end: "
+
divide
);
log
.
info
(
"end: "
+
divide
);
}
}
}
}
_03-aop-demo/src/main/java/com/matrix/nickel/aop/LogAspect.java
浏览文件 @
ec92d71d
package
com.matrix.nickel.aop
;
package
com.matrix.nickel.aop
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.*
;
import
org.aspectj.lang.annotation.*
;
import
org.aspectj.lang.reflect.SourceLocation
;
import
org.springframework.util.StringUtils
;
/**
/**
* 切面类
* 切面类
...
@@ -22,23 +26,34 @@ public class LogAspect {
...
@@ -22,23 +26,34 @@ public class LogAspect {
// 前置通知,方法执行之前切入
// 前置通知,方法执行之前切入
@Before
(
"execution(public int com.matrix.nickel.aop.MathCalculator.divide(int, int))"
)
@Before
(
"execution(public int com.matrix.nickel.aop.MathCalculator.divide(int, int))"
)
public
void
beforeInvoke
(){
public
void
beforeInvoke
(
JoinPoint
joinPoint
){
log
.
info
(
"before invoke...参数列表:"
);
Object
[]
args
=
joinPoint
.
getArgs
();
Signature
signature
=
joinPoint
.
getSignature
();
// 代理的目标类
Object
target
=
joinPoint
.
getTarget
();
// 封装后的代理类
Object
aThis
=
joinPoint
.
getThis
();
JoinPoint
.
StaticPart
staticPart
=
joinPoint
.
getStaticPart
();
SourceLocation
sourceLocation
=
joinPoint
.
getSourceLocation
();
String
longString
=
joinPoint
.
toLongString
();
String
shortString
=
joinPoint
.
toShortString
();
log
.
info
(
"before invoke...参数列表:"
+
StringUtils
.
arrayToCommaDelimitedString
(
args
));
}
}
// 后置通知,方法执行之后切入,不管正常还是异常返回,都会执行
// 后置通知,方法执行之后切入,不管正常还是异常返回,都会执行
@After
(
"com.matrix.nickel.aop.LogAspect.pointCut()"
)
@After
(
"com.matrix.nickel.aop.LogAspect.pointCut()"
)
public
void
afterInvoke
(){
public
void
afterInvoke
(
JoinPoint
joinPoint
){
log
.
info
(
"after invoke..."
);
log
.
info
(
"after invoke..."
);
}
}
// 正常返回通知
// 正常返回通知
@AfterReturning
(
"pointCut()
"
)
@AfterReturning
(
pointcut
=
"pointCut()"
,
returning
=
"result
"
)
public
void
returnInvoke
(){
public
void
returnInvoke
(
JoinPoint
joinPoint
,
Object
result
){
log
.
info
(
"method return...返回值:"
);
log
.
info
(
"method return...返回值:"
+
result
);
}
}
@AfterThrowing
(
"pointCut()
"
)
@AfterThrowing
(
pointcut
=
"pointCut()"
,
throwing
=
"ex
"
)
public
void
throwInvoke
(){
public
void
throwInvoke
(
JoinPoint
jp
,
Exception
ex
){
log
.
info
(
"method return...发生异常"
);
log
.
info
(
"method return...发生异常"
);
}
}
}
}
_03-aop-demo/src/main/resources/log4j2.xml
浏览文件 @
ec92d71d
...
@@ -2,7 +2,11 @@
...
@@ -2,7 +2,11 @@
<Configuration
status=
"WARN"
>
<Configuration
status=
"WARN"
>
<Appenders>
<Appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<PatternLayout
pattern=
"%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
/>
<!--<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>-->
<PatternLayout
pattern=
"%style{%d{HH:mm:ss}}{bright,#ffffff} %highlight{%-5level} [%style{%-20.-20t}{bright,blue}] %style{%-80.80l}{bright,yellow}: %msg%n%style{%throwable}{red}"
disableAnsi=
"false"
noConsoleNoAnsi=
"false"
/>
</Console>
</Console>
</Appenders>
</Appenders>
<Loggers>
<Loggers>
...
...
docs/idea中spring项目的构建运行.md
浏览文件 @
ec92d71d
导入到 idea 之后,spring 源码项目有两种构建运行方式!
[](
../images/idea中的两种编译.png
)
,intellij idea 和 gradle,建议使用 idea 的方式,这样更快
导入到 idea 之后,spring 源码项目有两种构建运行方式!
[](
../images/idea中的两种编译.png
)
,intellij idea 和 gradle,建议使用 idea 的方式,这样更快
File --> Settings --> Build, Execution, Deployment --> Build Tools --> Gradle 可以选择编译方式
选择 gradle 时,Build Project (Ctrl + F9) 会使用 gradle 编译 选择 intellij 时,Build Project (Ctrl + F9) 会使用自带的编译器编译
~~简单说就是:如果想使用 intellij idea 编译,就把 build.gradle 中的版本写成 1.5 如果想使用 gradle 编译,就把 build.gradle 中的版本写成 1.3~~ 该版本没有这个问题。
如果是 gradle 构建运行,则 spring aop, spring aspectj 这两个模块是可以编译成功的,gradle 自带了 AspectJ 的编译器;
如果是 idea 构建运行,则需要配置 java compiler 编译器为 Ajc,安装 aspectj1.9.20
如果想要使用 aop 功能,需要配置 !
[](
../images/配置facets开启AspectJ的编译.png
)
,最好安装插件 AspectJ
images/配置facets开启AspectJ的编译.png
0 → 100644
浏览文件 @
ec92d71d
此差异由.gitattributes 抑制。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录