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
98dd1563
Commit
98dd1563
authored
Dec 19, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复多数据源下enabled=false导致读取不到bean导致异常问题
parent
b65263fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
+24
-2
ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java
+24
-2
No files found.
ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java
View file @
98dd1563
...
...
@@ -20,6 +20,7 @@ import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import
com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties
;
import
com.alibaba.druid.util.Utils
;
import
com.ruoyi.common.enums.DataSourceType
;
import
com.ruoyi.common.utils.spring.SpringUtils
;
import
com.ruoyi.framework.config.properties.DruidProperties
;
import
com.ruoyi.framework.datasource.DynamicDataSource
;
...
...
@@ -50,15 +51,34 @@ public class DruidConfig
@Bean
(
name
=
"dynamicDataSource"
)
@Primary
public
DynamicDataSource
dataSource
(
DataSource
masterDataSource
,
DataSource
slaveDataSource
)
public
DynamicDataSource
dataSource
(
DataSource
masterDataSource
)
{
Map
<
Object
,
Object
>
targetDataSources
=
new
HashMap
<>();
targetDataSources
.
put
(
DataSourceType
.
MASTER
.
name
(),
masterDataSource
);
targetDataSources
.
put
(
DataSourceType
.
SLAVE
.
name
(),
slaveDataSource
);
setDataSource
(
targetDataSources
,
DataSourceType
.
SLAVE
.
name
(),
"slaveDataSource"
);
return
new
DynamicDataSource
(
masterDataSource
,
targetDataSources
);
}
/**
* 设置数据源
*
* @param targetDataSources 备选数据源集合
* @param sourceName 数据源名称
* @param beanName bean名称
*/
public
void
setDataSource
(
Map
<
Object
,
Object
>
targetDataSources
,
String
sourceName
,
String
beanName
)
{
try
{
DataSource
dataSource
=
SpringUtils
.
getBean
(
beanName
);
targetDataSources
.
put
(
sourceName
,
dataSource
);
}
catch
(
Exception
e
)
{
}
}
/**
* 去除监控页面底部的广告
*/
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
...
...
@@ -79,6 +99,7 @@ public class DruidConfig
public
void
init
(
javax
.
servlet
.
FilterConfig
filterConfig
)
throws
ServletException
{
}
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
...
...
@@ -93,6 +114,7 @@ public class DruidConfig
text
=
text
.
replaceAll
(
"powered.*?shrek.wang</a>"
,
""
);
response
.
getWriter
().
write
(
text
);
}
@Override
public
void
destroy
()
{
...
...
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