I have to remind myself that some birds aren't meant to be caged. Their feathers are just too bright. And when they fly away, the part of you that knows it was a sin to lock hem up DOES rejoice. Still, the place you live in is that much more drab and empty that they're gone. I guess I just miss my friend.
最近项目升级,Mybatis和PageHelper都采用较新版本,然而出现了一些版本不匹配的问题,现将问题总结如下:
问题一
项目中使用该配置:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
@Configuration
@ConditionalOnBean({SqlSessionFactory.class})
@EnableConfigurationProperties({PageHelperProperties.class})
@AutoConfigureAfter({MybatisAutoConfiguration.class})
public class PageHelperAutoConfiguration {
@Autowired
private List<SqlSessionFactory> sqlSessionFactoryList;
@Autowired
private PageHelperProperties properties;
public PageHelperAutoConfiguration() {
}
由于PageHelper中包含配置类PagehelperAutoConfiguration,需要MybatisAutoConfiguration,而上述mybatis版本并不包含该类,因此降级为1.1.7
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.7</version>
</dependency>
该依赖中包含MybatisAutoConfiguration,问题解决。
问题二
然而,项目启动中又出现问题:
nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: com.github.pagehelper.PageException:java.lang.ClassNotFoundException: mysql
查询发现是新版pagehelper配置发生变化的问题,
旧版配置分页插件数据库:pagehelper.dialect: mysql (该配置请去掉)
新版则是 pagehelper.helper-dialect: mysql (由于支持自动检测当前的数据库链接,该配置不需要)
问题解决。