forked from maventalker/simplemall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
guodeqiang
committed
Aug 15, 2017
1 parent
fb8985d
commit be4522a
Showing
7 changed files
with
246 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
msg-service/src/main/java/com/simplemall/micro/serv/msg/config/SqlSessionFactoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.simplemall.micro.serv.msg.config; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import org.springframework.transaction.annotation.TransactionManagementConfigurer; | ||
|
||
import com.simplemall.micro.serv.common.config.DataSourceProperties; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@MapperScan("com.simplemall.micro.serv.msg.mapper") | ||
public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Autowired | ||
private DataSourceProperties dataSourceProperties; | ||
|
||
/** | ||
* 创建sqlSessionFactoryBean | ||
* @return | ||
* @throws Exception | ||
*/ | ||
@Bean(name = "sqlSessionFactory") | ||
public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { | ||
SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); | ||
bean.setDataSource(dataSource); | ||
bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); | ||
|
||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); | ||
bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); | ||
|
||
return bean.getObject(); | ||
} | ||
|
||
@Bean | ||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { | ||
return new SqlSessionTemplate(sqlSessionFactory); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public PlatformTransactionManager annotationDrivenTransactionManager() { | ||
return new DataSourceTransactionManager(dataSource); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...service/src/main/java/com/simplemall/micro/serv/order/config/SqlSessionFactoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.simplemall.micro.serv.order.config; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import org.springframework.transaction.annotation.TransactionManagementConfigurer; | ||
|
||
import com.simplemall.micro.serv.common.config.DataSourceProperties; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@MapperScan("com.simplemall.micro.serv.order.mapper") | ||
public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Autowired | ||
private DataSourceProperties dataSourceProperties; | ||
|
||
/** | ||
* 创建sqlSessionFactoryBean | ||
* @return | ||
* @throws Exception | ||
*/ | ||
@Bean(name = "sqlSessionFactory") | ||
public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { | ||
SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); | ||
bean.setDataSource(dataSource); | ||
bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); | ||
|
||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); | ||
bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); | ||
|
||
return bean.getObject(); | ||
} | ||
|
||
@Bean | ||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { | ||
return new SqlSessionTemplate(sqlSessionFactory); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public PlatformTransactionManager annotationDrivenTransactionManager() { | ||
return new DataSourceTransactionManager(dataSource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...t-service/src/main/java/com/simplemall/micro/serv/pay/config/SqlSessionFactoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.simplemall.micro.serv.pay.config; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import org.springframework.transaction.annotation.TransactionManagementConfigurer; | ||
|
||
import com.simplemall.micro.serv.common.config.DataSourceProperties; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@MapperScan("com.simplemall.micro.serv.order.mapper") | ||
public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Autowired | ||
private DataSourceProperties dataSourceProperties; | ||
|
||
/** | ||
* 创建sqlSessionFactoryBean | ||
* @return | ||
* @throws Exception | ||
*/ | ||
@Bean(name = "sqlSessionFactory") | ||
public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { | ||
SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); | ||
bean.setDataSource(dataSource); | ||
bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); | ||
|
||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); | ||
bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); | ||
|
||
return bean.getObject(); | ||
} | ||
|
||
@Bean | ||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { | ||
return new SqlSessionTemplate(sqlSessionFactory); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public PlatformTransactionManager annotationDrivenTransactionManager() { | ||
return new DataSourceTransactionManager(dataSource); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...t-service/src/main/java/com/simplemall/micro/serv/prd/config/SqlSessionFactoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.simplemall.micro.serv.prd.config; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.mybatis.spring.SqlSessionFactoryBean; | ||
import org.mybatis.spring.SqlSessionTemplate; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import org.springframework.transaction.annotation.TransactionManagementConfigurer; | ||
|
||
import com.simplemall.micro.serv.common.config.DataSourceProperties; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@MapperScan("com.simplemall.micro.serv.order.mapper") | ||
public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Autowired | ||
private DataSourceProperties dataSourceProperties; | ||
|
||
/** | ||
* 创建sqlSessionFactoryBean | ||
* @return | ||
* @throws Exception | ||
*/ | ||
@Bean(name = "sqlSessionFactory") | ||
public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { | ||
SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); | ||
bean.setDataSource(dataSource); | ||
bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); | ||
|
||
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); | ||
bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); | ||
|
||
return bean.getObject(); | ||
} | ||
|
||
@Bean | ||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { | ||
return new SqlSessionTemplate(sqlSessionFactory); | ||
} | ||
|
||
@Bean | ||
@Override | ||
public PlatformTransactionManager annotationDrivenTransactionManager() { | ||
return new DataSourceTransactionManager(dataSource); | ||
} | ||
} |