walkingWind commented on issue #1842: XA Transaction missing the data source URL: https://github.com/apache/incubator-shardingsphere/issues/1842#issuecomment-459188038 # here is my code snippet `application.yml` ``` mybatis: mapper-locations: classpath*:mapper/*Mapper.xml type-aliases-package: com.tsm.shardingjdbctest.domain sharding: jdbc: data-sources: mydb_ms0: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://10.0.2.238:3306/mydb_ms?characterEncoding=utf8&useSSL=false username: root password: 123456 mydb_ms0_slave0: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://xx.xx.xx.xx:xx/mydb1?characterEncoding=utf8&useSSL=false username: root password: 123456 mydb_ms0_slave1: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://xx.xx.xx.xx:xx/mydb2?characterEncoding=utf8&useSSL=false username: root password: 123456 mydb_ms1: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://xx.xx.xx.xx:xx/mydb_ms?characterEncoding=utf8&useSSL=false username: root password: 123456 mydb_ms1_slave0: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://xx.xx.xx.xx:xx/mydb1?characterEncoding=utf8&useSSL=false username: root password: 123456 mydb_ms1_slave1: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://xx.xx.xx.xx:xx/mydb2?characterEncoding=utf8&useSSL=false username: root password: 123456 master-slave-rule: ds_ms0: master-data-source-name: mydb_ms0 slave-data-source-names: [mydb_ms0_slave0,mydb_ms0_slave0] load-balance-algorithm-type: round_robin ds_ms1: master-data-source-name: mydb_ms1 slave-data-source-names: [mydb_ms1_slave0,mydb_ms1_slave1] load-balance-algorithm-type: round_robin sharding-rule: tables: user: actual-data-nodes: ds_ms${0..1}.user${1..3} database-strategy: inline: sharding-column: age algorithm-inline-expression: ds_ms${age % 2} table-strategy: inline: sharding-column: age algorithm-inline-expression: user${age % 3+1} age: actual-data-nodes: ds_ms${0..1}.age${1..2} database-strategy: inline: sharding-column: id algorithm-inline-expression: ds_ms${id % 2} table-strategy: inline: sharding-column: id algorithm-inline-expression: age${id % 2+1} ``` `ShardingjdbcTestApplication.java` ``` @ComponentScan("com.tsm.shardingjdbctest") @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) @SpringBootApplication(exclude = JtaAutoConfiguration.class) @ComponentScan("io.shardingsphere.transaction.aspect") public class ShardingjdbcTestApplication { public static void main(String[] args) { SpringApplication.run(ShardingjdbcTestApplication.class, args); } } ``` `DataSourceConfig.java` ``` DataSource dataSource =ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingEnvironment.initShardingRule(), new HashMap<>(),new Properties()); ``` `TestController.java` ``` @GetMapping("/back") @Transactional @ShardingTransactionType(TransactionType.XA) public String test1111() throws Exception{ User user1=new User(); user1.setAge(24+(int)(Math.random()*60)*6); user1.setName("qq"); System.out.println(JSON.toJSONString(testMapper.addOneUser(user1))); User user2=new User(); user2.setAge(25+(int)(Math.random()*60)*6); user2.setName("qq"); System.out.println(JSON.toJSONString(testMapper.addOneUser(user2))); return "success"; } ``` I am sure datasource was initialized, because it worked well if i delete @ShardingTransactionType(TransactionType.XA) in my TestController. I don't have `jta.properties`, is that necessary to have a `jta.properties`? If so, why the exception description is that about data source? @cherrylzhao
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
