Springboot整合pagehelper

一、开发环境 
spring boot 2.0.3.RELEASE

二、gradle依赖

compile group: 'com.github.pagehelper', name: 'pagehelper', version: '5.0.4'

 compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.2.10'

三、application.yml配置

 


pagehelper:
  dialect: MYSQL
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

如上配置会报错:

Caused by: com.github.pagehelper.PageException: java.lang.ClassNotFoundException: MYSQL
	at com.github.pagehelper.PageInterceptor.setProperties(PageInterceptor.java:242)
	at com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration.addPageInterceptor(PageHelperAutoConfiguration.java:78)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:365)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:308)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135)
	... 42 more

解决方法:去掉配置dialect: MYSQL,即可

四、问题
配置多个yml,application.yml,application-dev.yml,配置详情如下:

application.yml

spring:
  profiles:
    active: dev
pagehelper:
  dialect: MYSQL
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

 application-dev.yml

pagehelper:
  #dialect: MYSQL
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

如上配置,当前激活的yml为application-dev.ym,但是在实际测试中,如果不注释掉application.yml 的 dialect: MYSQL,依赖会报com.github.pagehelper.PageException: java.lang.ClassNotFoundException: MYSQL的错误。即Paghelper读取此配置是从application.ym读取,而不是当前激活的application-dev.ym中。

你可能感兴趣的:(springboot)