当前位置:首页>正文

什么是mybatis框架的读写分离 求教Springboot mybatis的配置

2023-05-21 16:18:45 互联网 未知

什么是mybatis框架的读写分离

mysql-proxy是官方提供的mysql中间件产品可以实现负载平衡,读写分离,failover等,但其不支持大数据量的分库分表且性能较差。 其他mysql开源中间件产品有:Atlas,cobar,tddl。你可以查阅一下相关信息和各自的优缺点。

求教Springboot mybatis的配置

@Configuration
@EnableTransactionManagement
@MapperScan("com.*.*.mapper")
public class DataBaseConfig {

private final Logger log = LoggerFactory.getLogger(DataBaseConfig.class)

@Bean
@Primary
@ConfigurationProperties(prefix = "datasource.primary")
public DataSource dataSource() {
log.debug("Configuring Datasource")
return new DruidDataSource()
}

@Bean
public PlatformTransactionManager txManager() {
return new DataSourceTransactionManager(dataSource())
}

@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {

SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean()
sqlSessionFactoryBean.setDataSource(dataSource())

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver()

sqlSessionFactoryBean.setMapperLocations(resolver
.getResources("classpath:/mapper/*.xml"))
return sqlSessionFactoryBean.getObject()
}

}

ssm框架中spring,springMVC,mybatis分别什么作用

使用springMVC作为系统的整体基础架构,负责MVC的分离,在springMVC框架的模型部分,控制业务跳转,利用mybatis框架对持久层提供支持,Spring做管理,管理springMVC和mybatis。

SpringBoot中如何分开写配置文件

案例:
1.application.properties

2.application-cus1.properties

3.application-cus1.properties

4.application-cus1.properties


5.controller

6.结果

spring和mybatis整合问题

import org.apache.ibatis.session.SqlSessionFactory
import org.springframework.context.ApplicationContext
import org.springframework.context.support.FileSystemXmlApplicationContext

public class MyBatisUtil  {   

    private  final static SqlSessionFactory sqlSessionFactory   

    static {   
     ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:applicationContext.xml") 
     sqlSessionFactory = (SqlSessionFactory)ac.getBean("sqlSessionFactory") 
    }   

    public static SqlSessionFactory getSqlSessionFactory() {   
       return sqlSessionFactory   
    }   
}mybatis 的注解没有提供注入sqlSessionFactory的方法。你可以通过上面的方式获得sqlSessionfanctory