zoukankan      html  css  js  c++  java
  • 分库操作(无事务)

    Product库:

    @Configuration
    @MapperScan(basePackages = ProductConfig.PACKAGE, sqlSessionFactoryRef = "productSqlSessionFactory")
    public class ProductConfig {
        // 精确到 cluster 目录,以便跟其他数据源隔离
        static final String PACKAGE = "com.yangshan.exportData.mapper.product";
        static final String MAPPER_LOCATION = "classpath:mapper/product/*.xml";
    
        @Value("${product.datasource.url}")
        private String url;
    
        @Value("${product.datasource.username}")
        private String user;
    
        @Value("${product.datasource.password}")
        private String password;
    
        @Value("${product.datasource.driverClassName}")
        private String driverClass;
    
        @Bean(name = "productDataSource")
        public DataSource productDataSource() {
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setDriverClassName(driverClass);
            dataSource.setUrl(url);
            dataSource.setUsername(user);
            dataSource.setPassword(password);
            return dataSource;
        }
    
        @Bean(name = "productTransactionManager")
        public DataSourceTransactionManager productTransactionManager() {
            return new DataSourceTransactionManager(productDataSource());
        }
    
        @Bean(name = "productSqlSessionFactory")
        public SqlSessionFactory productSqlSessionFactory(@Qualifier("productDataSource") DataSource productDataSource) throws Exception {
            final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
            sessionFactory.setDataSource(productDataSource);
            sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(ProductConfig.MAPPER_LOCATION));
            return sessionFactory.getObject();
        }
    }

    Order库:

    @Configuration
    @MapperScan(basePackages = OrderConfig.PACKAGE, sqlSessionFactoryRef = "orderSqlSessionFactory")
    public class OrderConfig {
        // 精确到 cluster 目录,以便跟其他数据源隔离
        static final String PACKAGE = "com.yangshan.exportData.mapper.order";
        static final String MAPPER_LOCATION = "classpath:mapper/order/*.xml";
    
        @Value("${order.datasource.url}")
        private String url;
        @Value("${order.datasource.username}")
        private String user;
        @Value("${order.datasource.password}")
        private String password;
        @Value("${order.datasource.driverClassName}")
        private String driverClass;
    
        @Bean(name = "orderDataSource")
        public DataSource orderDataSource() {
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setDriverClassName(driverClass);
            dataSource.setUrl(url);
            dataSource.setUsername(user);
            dataSource.setPassword(password);
            return dataSource;
        }
    
        @Bean(name = "orderTransactionManager")
        public DataSourceTransactionManager orderTransactionManager() {
            return new DataSourceTransactionManager(orderDataSource());
        }
    
        @Bean(name = "orderSqlSessionFactory")
        public SqlSessionFactory orderSqlSessionFactory(@Qualifier("orderDataSource") DataSource orderDataSource, MybatisProperties mybatisProperties) throws Exception {
            final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
            sessionFactory.setDataSource(orderDataSource);
            sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(OrderConfig.MAPPER_LOCATION));
            sessionFactory.setConfiguration(mybatisProperties.getConfiguration());
            return sessionFactory.getObject();
        }
    }

    等等。。。

  • 相关阅读:
    大数的加法
    tomcat jdbc DataSource资料
    转 spring的事务传播
    jmeter系列七(Visualizer的TestElement-ResultCollector)
    jmeter系列六(processor)
    jmeter系列五(Config配置元素)
    jmeter系列四(Visualizer)
    jmeter系列三(控制器controller)
    jmeter系列二(jmeter engine相关)
    jmeter系列一(jmeter界面相关无TestBean)
  • 原文地址:https://www.cnblogs.com/yifanSJ/p/12100744.html
Copyright © 2011-2022 走看看