`
y806839048
  • 浏览: 1091535 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

springBoot去了自动装配的start可以改用手动转配(处理依赖业务子项目的重复依赖,用底层的模块, 避免版本问题)

阅读更多

 

在集成mybatis 和 tkmapper等时候,可以有两种选择,1,用springboot 的start 实现自动装配  2,普通的依赖形式,自己用@configure手动配置即可,无需开启

 

 

 

 1 自动装配 (自动装配mapper,mybatis,pagehepler,pagehelper中有mybatis的依赖 所以mybatis的start无需写 )---自动装配中有好多重复依赖 看下有些可以省略

 (例如分页插件中有mybatis)

 

 

=============

分页插件中就有依赖

 

<dependency>

<groupId>com.github.pagehelper</groupId>

<artifactId>pagehelper-spring-boot-starter</artifactId>

<version>1.1.0</version>

</dependency>

 

 

  //<dependency>

  //          <groupId>org.mybatis.spring.boot</groupId>

   //         <artifactId>mybatis-spring-boot-starter</artifactId>

    //        <version>1.3.1</version>

     //   </dependency>

 

 

mapper的自动装配  ---自动装配的主要工作就是修改默认配置

 

<dependency>

            <groupId>tk.mybatis</groupId>

            <artifactId>mapper-spring-boot-starter</artifactId>

            <version>1.1.1</version>

        </dependency>

 

 

@SpringBootApplication

@EnableTransactionManagement

@MapperScan(basePackages = "com.houbank.bank.web.mapper")

public class BankWebApplication extends SpringBootServletInitializer{}

 

mapper.mappers=com.houbank.bank.web.util.MyMapper   自定义的通用mapper(注意自定的MyMapper不可以和普通的mapper放在一个路径中(否则框架扫描普通的时候会出错))

mapper.not-empty=false

mapper.identity=MYSQL

 

 

手动装配:

 

去了自动装配的start可以改用手动转配(处理依赖业务子项目的重复依赖,用底层的模块)

<dependency>-----例如直接用底层项目的

            <groupId>tk.mybatis</groupId>

            <artifactId>mapper</artifactId>

            <version>3.4.0</version>

        </dependency>

 

 

@Configuration

public class MyBatisMapperScannerConfig{

 @Bean

 public MapperScannerConfigurer mapperScannerConfigurer(){

  MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();

  mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");

  mapperScannerConfigurer.setBasePackage("com.houbank.bank.mapper.dao");//扫描该路径下的dao

  Properties properties = new Properties();

  properties.setProperty("mappers", "com.houbank.bank.mapper.MyMapper");//通用dao

  properties.setProperty("notEmpty", "false");

  properties.setProperty("IDENTITY", "MYSQL");

  mapperScannerConfigurer.setProperties(properties);

  return mapperScannerConfigurer;

 }

}

 

 

@PropertySource({

    "classpath:property-brh.properties",

    "classpath:property-houbank.properties",

    "classpath:property-zbank.properties",

    "classpath:property-sanxiang.properties"

})

@SpringBootApplication

@EnableTransactionManagement

public class RunApiApplication extends SpringBootServletInitializer {}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics