NutzCN Logo
问答 springboot2多maven模块mybatis和PageHelper配置问题
发布于 2370天前 作者 qq_99c1b36f 3078 次浏览 复制 上一个帖子 下一个帖子
标签:

我有一个项目,采用的maven多模块,每一个模块都是springboot2 + mybatis + PageHelper。结构如下:
---abc项目
--------admin模块:[dao,service,mapper.xml; 系统配置相关操作]
--------common模块:[util,entity,提供所有实体类]
--------serviceA模块:[dao,service,mapper.xml; 业务A相关操作]
--------serviceB模块:[dao,service,mapper.xml; 业务B相关操作]
--------web模块:[页面展示]


下面是admin模块的数据方面的配置:

@Configuration
public class Admin_MyBatisCfg {

	@Bean
	public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
		SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
		bean.setDataSource(dataSource);

		// 分页插件
		PageHelper pageHelper = new PageHelper();
		Properties properties = new Properties();
		properties.setProperty("reasonable", "true");
		properties.setProperty("supportMethodsArguments", "true");
		properties.setProperty("returnPageInfo", "check");
		properties.setProperty("params", "count=countSql");
		pageHelper.setProperties(properties);

		// 添加插件
		bean.setPlugins(new Interceptor[] { pageHelper });

		// 添加XML目录
		ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
		try {
			bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
			bean.setConfigLocation(resolver.getResource("classpath:mybatis-conf.xml"));
			return bean.getObject();
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	@Bean(name = "sqlSession")
	public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		return new SqlSessionTemplate(sqlSessionFactory);
	}

	@Bean("admin_mapper_scanner_cfg)")
	public MapperScannerConfigurer mapperScannerConfigurer() {
		MapperScannerConfigurer config = new MapperScannerConfigurer();
		config.setBasePackage("com.sdcm.admin.dao");
		return config;
	}

}

server:
  port: 10002

spring:
  datasource:
    name: pmpds
    url: jdbc:mysql://192.168.0.241:3306/pmpmain?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
    username: sdcm
    password: Sdcm_123456
    # 使用druid数据源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    filters: stat
    maxActive: 20
    initialSize: 1
    maxWait: 60000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    maxPoolPreparedStatementPerConnectionSize: 20
    maxOpenPreparedStatements: 20

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.sdcm.common.entity

mapper:
  mappers:  com.sdcm.admin.dao
  not-empty: false
  identity: MYSQL

#pagehelper
pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql
  returnPageInfo: check

现在遇到一些问题:
1. 非微服务,我这样分maven模块合理吗?
2. datasource,SqlSessionFactory是不是在整个abc项目里同一时刻只能存在一份?
3. 我的配置是否正确?

10 回复

额,这个问题不解决,就没有机会了解了

我们都不用springboot ,没法解决,你去开源中国提问吧

他回的帖子的内容都是路过,你等什么

他回你的帖子的内容都是路过,你等什么,锁贴了。

添加回复
请先登陆
回到顶部