Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringBoot-kwan
提交
1f307777
S
SpringBoot-kwan
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringBoot-kwan
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringBoot-kwan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1f307777
编写于
12月 19, 2022
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:配置拦截器
上级
3d06f36f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
152 addition
and
3 deletion
+152
-3
pom.xml
pom.xml
+20
-2
src/main/java/com/kwan/springbootkwan/aop/LogAspect.java
src/main/java/com/kwan/springbootkwan/aop/LogAspect.java
+51
-0
src/main/java/com/kwan/springbootkwan/config/DataSourceConfig.java
...java/com/kwan/springbootkwan/config/DataSourceConfig.java
+24
-0
src/main/java/com/kwan/springbootkwan/config/MyInterceptor.java
...in/java/com/kwan/springbootkwan/config/MyInterceptor.java
+33
-0
src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
...n/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
+24
-1
未找到文件。
pom.xml
浏览文件 @
1f307777
...
...
@@ -74,8 +74,15 @@
<artifactId>
spring-boot-devtools
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
@@ -92,5 +99,16 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>
**/*.xml
</include>
</includes>
</resource>
<resource>
<directory>
src/main/resources
</directory>
</resource>
</resources>
</build>
</project>
\ No newline at end of file
src/main/java/com/kwan/springbootkwan/aop/LogAspect.java
0 → 100644
浏览文件 @
1f307777
package
com.kwan.springbootkwan.aop
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.*
;
import
org.springframework.stereotype.Component
;
/**
* AOP 实现方法拦截
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:17
*/
@Component
@Aspect
public
class
LogAspect
{
@Pointcut
(
value
=
"execution(* com.kwan.springbootkwan.service.*.*(..))"
)
public
void
pcl
()
{
}
@Before
(
value
=
"pcl()"
)
public
void
before
(
JoinPoint
point
)
{
String
name
=
point
.
getSignature
().
getName
();
System
.
out
.
println
(
name
+
"方法开始执行 ..."
);
}
@After
(
value
=
"pcl()"
)
public
void
after
(
JoinPoint
point
)
{
String
name
=
point
.
getSignature
().
getName
();
System
.
out
.
println
(
name
+
"方法执行结束 ..."
);
}
@AfterReturning
(
value
=
"pcl()"
,
returning
=
"result"
)
public
void
afterReturning
(
JoinPoint
point
,
Object
result
)
{
String
name
=
point
.
getSignature
().
getName
();
System
.
out
.
println
(
name
+
"方法返回值为:"
+
result
);
}
@AfterThrowing
(
value
=
"pcl()"
,
throwing
=
"e"
)
public
void
afterThrowing
(
JoinPoint
point
,
Exception
e
)
{
String
name
=
point
.
getSignature
().
getName
();
System
.
out
.
println
(
name
+
"方法抛异常了,异常是:"
+
e
.
getMessage
());
}
@Around
(
"pcl()"
)
public
Object
around
(
ProceedingJoinPoint
pjp
)
throws
Throwable
{
return
pjp
.
proceed
();
}
}
src/main/java/com/kwan/springbootkwan/config/DataSourceConfig.java
0 → 100644
浏览文件 @
1f307777
package
com.kwan.springbootkwan.config
;
import
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.sql.DataSource
;
@Configuration
public
class
DataSourceConfig
{
@Bean
@ConfigurationProperties
(
"spring.datasource.one"
)
DataSource
dataSourceOne
()
{
return
DruidDataSourceBuilder
.
create
().
build
();
}
@Bean
@ConfigurationProperties
(
"spring.datasource.two"
)
DataSource
dataSourceTwo
()
{
return
DruidDataSourceBuilder
.
create
().
build
();
}
}
src/main/java/com/kwan/springbootkwan/config/MyInterceptor.java
0 → 100644
浏览文件 @
1f307777
package
com.kwan.springbootkwan.config
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* 自定义拦截器
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2022/12/19 16:14
*/
public
class
MyInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
System
.
out
.
println
(
"MyInterceptor>>>>>>>>>preHandle"
);
return
true
;
}
@Override
public
void
postHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
ModelAndView
modelAndView
)
throws
Exception
{
System
.
out
.
println
(
"MyInterceptor>>>>>>>>>postHandle"
);
}
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
System
.
out
.
println
(
"MyInterceptor>>>>>>>>>afterCompletion"
);
}
}
src/main/java/com/kwan/springbootkwan/config/MyWebMvcConfig.java
浏览文件 @
1f307777
...
...
@@ -2,11 +2,12 @@ package com.kwan.springbootkwan.config;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
/**
* 全局
拦截器
-跨域配置
* 全局
webconfig
-跨域配置
*
* @author : qinyingjie
* @version : 2.2.0
...
...
@@ -14,12 +15,34 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
*/
@Configuration
public
class
MyWebMvcConfig
implements
WebMvcConfigurer
{
/**
* 配置静态资源
*
* @param registry
*/
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/static/**"
)
.
addResourceLocations
(
"classpath:/static/"
);
}
/**
* 配置拦截器
*
* @param registry
*/
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
new
MyInterceptor
())
.
addPathPatterns
(
"/**"
)
.
excludePathPatterns
(
"/hello"
);
}
/**
* 配置全局跨域
*
* @param registry
*/
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/book/**"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录