Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jz-dmp-service
Project
Project
Details
Activity
Releases
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
姚本章
jz-dmp-service
Commits
188a4e81
Commit
188a4e81
authored
Dec 18, 2020
by
sml
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交
parent
a664f6f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
0 deletions
+170
-0
DataSourceConfig1.java
src/main/java/com/jz/dmp/config/DataSourceConfig1.java
+85
-0
DataSourceConfig2.java
src/main/java/com/jz/dmp/config/DataSourceConfig2.java
+85
-0
11
src/main/resources/mapper/dmp/11
+0
-0
No files found.
src/main/java/com/jz/dmp/config/DataSourceConfig1.java
0 → 100644
View file @
188a4e81
package
com
.
jz
.
dmp
.
config
;
import
javax.sql.DataSource
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
com.zaxxer.hikari.HikariConfig
;
import
com.zaxxer.hikari.HikariDataSource
;
@Configuration
@MapperScan
(
basePackages
=
DataSourceConfig1
.
PACKAGE
,
sqlSessionFactoryRef
=
"sqlSessionFactory1"
)
public
class
DataSourceConfig1
{
static
final
String
PACKAGE
=
"com.jz.dmp.modules.dao"
;
@Value
(
"${spring.datasource1.driver-class-name}"
)
private
String
driverClassName
;
@Value
(
"${spring.datasource1.url}"
)
private
String
url
;
@Value
(
"${spring.datasource1.username}"
)
private
String
userName
;
@Value
(
"${spring.datasource1.password}"
)
private
String
password
;
@Value
(
"${spring.datasource1.hikari.connectionTimeout}"
)
private
long
connectionTimeout
;
@Value
(
"${spring.datasource1.hikari.idleTimeout}"
)
private
long
idleTimeout
;
@Value
(
"${spring.datasource1.hikari.maxLifetime}"
)
private
long
maxLifetime
;
@Value
(
"${spring.datasource1.hikari.maximumPoolSize}"
)
private
int
maximumPoolSize
;
@Bean
(
name
=
"dataSource1"
)
@Primary
public
DataSource
dataSource1
()
{
HikariConfig
config
=
new
HikariConfig
();
config
.
setDriverClassName
(
driverClassName
);
config
.
setJdbcUrl
(
url
);
config
.
setUsername
(
userName
);
config
.
setPassword
(
password
);
config
.
setConnectionTimeout
(
connectionTimeout
);
config
.
setIdleTimeout
(
idleTimeout
);
config
.
setMaxLifetime
(
maxLifetime
);
config
.
setMaximumPoolSize
(
maximumPoolSize
);
HikariDataSource
dataSource
=
new
HikariDataSource
(
config
);
return
dataSource
;
}
@Bean
(
name
=
"sqlSessionFactory1"
)
@Primary
public
SqlSessionFactory
sqlSessionFactory1
(
@Qualifier
(
"dataSource1"
)
DataSource
dataSource
)
throws
Exception
{
final
SqlSessionFactoryBean
sessionFactory
=
new
SqlSessionFactoryBean
();
sessionFactory
.
setDataSource
(
dataSource
);
try
{
sessionFactory
.
setConfigLocation
(
new
ClassPathResource
(
"mybatis-config.xml"
));
sessionFactory
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
()
.
getResources
(
"classpath:mapper/dmp/*.xml"
));
return
sessionFactory
.
getObject
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Bean
(
name
=
"transactionManager1"
)
@Primary
public
DataSourceTransactionManager
transactionManager1
()
{
return
new
DataSourceTransactionManager
(
dataSource1
());
}
}
src/main/java/com/jz/dmp/config/DataSourceConfig2.java
0 → 100644
View file @
188a4e81
package
com
.
jz
.
dmp
.
config
;
import
javax.sql.DataSource
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.mybatis.spring.SqlSessionFactoryBean
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.jdbc.datasource.DataSourceTransactionManager
;
import
com.zaxxer.hikari.HikariConfig
;
import
com.zaxxer.hikari.HikariDataSource
;
/**
* api数据库连接
* @author pactera
*
*/
//@Configuration
//@MapperScan(basePackages = DataSourceConfig2.PACKAGE, sqlSessionFactoryRef = "sqlSessionFactory2")
public
class
DataSourceConfig2
{
static
final
String
PACKAGE
=
"com.jz.dmp.web.ui.modules.api.repository"
;
@Value
(
"${spring.datasource2.driver-class-name}"
)
private
String
driverClassName
;
@Value
(
"${spring.datasource2.url}"
)
private
String
url
;
@Value
(
"${spring.datasource2.username}"
)
private
String
userName
;
@Value
(
"${spring.datasource2.password}"
)
private
String
password
;
@Value
(
"${spring.datasource2.hikari.connectionTimeout}"
)
private
long
connectionTimeout
;
@Value
(
"${spring.datasource2.hikari.idleTimeout}"
)
private
long
idleTimeout
;
@Value
(
"${spring.datasource2.hikari.maxLifetime}"
)
private
long
maxLifetime
;
@Value
(
"${spring.datasource2.hikari.maximumPoolSize}"
)
private
int
maximumPoolSize
;
@Bean
(
name
=
"dataSource2"
)
public
DataSource
dataSource2
()
{
HikariConfig
config
=
new
HikariConfig
();
config
.
setDriverClassName
(
driverClassName
);
config
.
setJdbcUrl
(
url
);
config
.
setUsername
(
userName
);
config
.
setPassword
(
password
);
config
.
setConnectionTimeout
(
connectionTimeout
);
config
.
setIdleTimeout
(
idleTimeout
);
config
.
setMaxLifetime
(
maxLifetime
);
config
.
setMaximumPoolSize
(
maximumPoolSize
);
HikariDataSource
dataSource
=
new
HikariDataSource
(
config
);
return
dataSource
;
}
@Bean
(
name
=
"sqlSessionFactory2"
)
public
SqlSessionFactory
sqlSessionFactory2
(
@Qualifier
(
"dataSource2"
)
DataSource
dataSource
)
throws
Exception
{
final
SqlSessionFactoryBean
sessionFactory
=
new
SqlSessionFactoryBean
();
sessionFactory
.
setDataSource
(
dataSource
);
try
{
sessionFactory
.
setConfigLocation
(
new
ClassPathResource
(
"mybatis-config.xml"
));
sessionFactory
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
()
.
getResources
(
"classpath:mapper/api/*.xml"
));
return
sessionFactory
.
getObject
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
@Bean
(
name
=
"transactionManager2"
)
public
DataSourceTransactionManager
transactionManager2
()
{
return
new
DataSourceTransactionManager
(
dataSource2
());
}
}
src/main/resources/mapper/dmp/11
0 → 100644
View file @
188a4e81
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