Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
71ff337e
Commit
71ff337e
authored
Jul 26, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多数据源支持类注解(允许继承父类的注解)
parent
9e2c6858
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
+28
-7
ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataSource.java
+5
-1
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
+23
-6
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataSource.java
View file @
71ff337e
package
com
.
ruoyi
.
common
.
annotation
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
...
...
@@ -11,8 +13,10 @@ import com.ruoyi.common.enums.DataSourceType;
*
* @author ruoyi
*/
@Target
(
ElementType
.
METHOD
)
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
TYPE
}
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
public
@interface
DataSource
{
/**
...
...
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
View file @
71ff337e
...
...
@@ -26,7 +26,8 @@ public class DataSourceAspect
{
protected
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Pointcut
(
"@annotation(com.ruoyi.common.annotation.DataSource)"
)
@Pointcut
(
"@annotation(com.ruoyi.common.annotation.DataSource)"
+
"|| @within(com.ruoyi.common.annotation.DataSource)"
)
public
void
dsPointCut
()
{
...
...
@@ -35,11 +36,7 @@ public class DataSourceAspect
@Around
(
"dsPointCut()"
)
public
Object
around
(
ProceedingJoinPoint
point
)
throws
Throwable
{
MethodSignature
signature
=
(
MethodSignature
)
point
.
getSignature
();
Method
method
=
signature
.
getMethod
();
DataSource
dataSource
=
method
.
getAnnotation
(
DataSource
.
class
);
DataSource
dataSource
=
getDataSource
(
point
);
if
(
StringUtils
.
isNotNull
(
dataSource
))
{
...
...
@@ -56,4 +53,24 @@ public class DataSourceAspect
DynamicDataSourceContextHolder
.
clearDataSourceType
();
}
}
/**
* 获取需要切换的数据源
*/
public
DataSource
getDataSource
(
ProceedingJoinPoint
point
)
{
MethodSignature
signature
=
(
MethodSignature
)
point
.
getSignature
();
Class
<?
extends
Object
>
targetClass
=
point
.
getTarget
().
getClass
();
DataSource
targetDataSource
=
targetClass
.
getAnnotation
(
DataSource
.
class
);
if
(
StringUtils
.
isNotNull
(
targetDataSource
))
{
return
targetDataSource
;
}
else
{
Method
method
=
signature
.
getMethod
();
DataSource
dataSource
=
method
.
getAnnotation
(
DataSource
.
class
);
return
dataSource
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment