shangwq commented on issue #16117:
URL:
https://github.com/apache/shardingsphere/issues/16117#issuecomment-1070583946
it's a simple project
the main dependencies is
```xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.1.0</version>
</dependency>
```
application.properties
```properties
mybatis.mapper-locations = classpath*:mapper/*.xml
mybatis.configuration.map-underscore-to-camel-case = true
spring.shardingsphere.props.sql-show = true
spring.shardingsphere.datasource.names = master,slave
spring.shardingsphere.datasource.master.type =
com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.master.driver-class-name =
com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.master.jdbc-url =
jdbc:mysql://xxx:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&allowMultiQueries=true
spring.shardingsphere.datasource.master.username = xxx
spring.shardingsphere.datasource.master.password = xxx
spring.shardingsphere.datasource.slave.type =
com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.slave.driver-class-name =
com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.slave.jdbc-url =
jdbc:mysql://xxx:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&allowMultiQueries=true
spring.shardingsphere.datasource.slave.username = xxx
spring.shardingsphere.datasource.slave.password = xxx
```
Unit Test
```java
@SpringBootApplication
@MapperScan(basePackages = {"com.example.demo"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Transactional(rollbackFor = Exception.class)
@SpringBootTest(classes = {DemoApplication.class})
class DemoApplicationTests {
@Resource
private AddressMapper addressMapper;
@Test
void test() {
AddressModel address = new AddressModel();
address.setAddressId(111L);
address.setContactMobile("18888888888");
address.setContactName("Tom");
addressMapper.insertSelective(address);
}
}
```
normally when the unit test completed, the transaction will be roll back.
but actually the data `Tom` was still in database, do not roll back.
when i change spring boot version to 2.4.13, the transaction can roll back
successfully
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]