mybatis引入mybatis-plus

mybatis配置的sqlSessionFactory

    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource jdbcDatasource) throws Exception {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(jdbcDatasource);
        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
        configuration.setLazyLoadingEnabled(false);
        configuration.setMultipleResultSetsEnabled(false);
        configuration.setLocalCacheScope(LocalCacheScope.SESSION);
        configuration.setLogImpl(org.apache.ibatis.logging.stdout.StdOutImpl.class);//输出打印sql
        factoryBean.setPlugins(plugin());
        //把查询出来的字段转换成小写
        MapWrapperFactory mapWrapperFactory = new MapWrapperFactory();
        configuration.setObjectWrapperFactory(mapWrapperFactory);

        factoryBean.setConfiguration(configuration);
        factoryBean.setTypeAliasesPackage("com.test");
        // 加载MyBatis配置文件
        PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        // 能加载多个,所以可以配置通配符(如:classpath*:mapper/**/*.xml)
        factoryBean.setMapperLocations(resourcePatternResolver.
                getResources("classpath*:mapper/**/*.xml"));
        configuration.setCallSettersOnNulls(true);
        return factoryBean.getObject();
}

引入mybatis-plus后,代码 this.list()报错,Invalid bound statement (not found):SelectList()

修改sqlSessionFactory,注意使用下面的配置

MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
 com.baomidou.mybatisplus.core.MybatisConfiguration configuration = new com.baomidou.mybatisplus.core.MybatisConfiguration();

    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource jdbcDatasource) throws Exception {
        MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
        factoryBean.setDataSource(jdbcDatasource);
        com.baomidou.mybatisplus.core.MybatisConfiguration configuration = new com.baomidou.mybatisplus.core.MybatisConfiguration();
        configuration.setLazyLoadingEnabled(false);
        configuration.setMultipleResultSetsEnabled(false);
        configuration.setLocalCacheScope(LocalCacheScope.SESSION);
        configuration.setLogImpl(org.apache.ibatis.logging.stdout.StdOutImpl.class);//输出打印sql        //把查询出来的字段转换成小写
        MapWrapperFactory mapWrapperFactory = new MapWrapperFactory();
        configuration.setObjectWrapperFactory(mapWrapperFactory);

        factoryBean.setConfiguration(configuration);
        factoryBean.setTypeAliasesPackage("com.test");
        // 加载MyBatis配置文件
        PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        // 能加载多个,所以可以配置通配符(如:classpath*:mapper/**/*.xml)
        factoryBean.setMapperLocations(resourcePatternResolver.
                getResources("classpath*:mapper/**/*.xml"));
        configuration.setCallSettersOnNulls(true);
		return factoryBean.getObject();
    }

SelectList()是   

public abstract List getMethodList();

public abstract class AbstractSqlInjector implements ISqlInjector {
    public abstract List getMethodList();   
}

这个有两个实现类,默认是DefaultSqlInjector中的

public class DefaultSqlInjector extends AbstractSqlInjector {

    @Override
    public List getMethodList() {
        return Stream.of(
            new Insert(),
            new Delete(),
            new DeleteByMap(),
            new DeleteById(),
            new DeleteBatchByIds(),
            new Update(),
            new UpdateById(),
            new SelectById(),
            new SelectBatchByIds(),
            new SelectByMap(),
            new SelectOne(),
            new SelectCount(),
            new SelectMaps(),
            new SelectMapsPage(),
            new SelectObjs(),
            new SelectList(),
            new SelectPage()
        ).collect(toList());
    }
}

调试堆栈信息

mybatis引入mybatis-plus_第1张图片

 

addMappedStatement:791, Configuration (org.apache.ibatis.session)
addMappedStatement:102, MybatisConfiguration (com.baomidou.mybatisplus.core)
addMappedStatement:297, MapperBuilderAssistant (org.apache.ibatis.builder)
addMappedStatement:245, AbstractMethod (com.baomidou.mybatisplus.core.injector)
addInsertMappedStatement:207, AbstractMethod (com.baomidou.mybatisplus.core.injector)
injectMappedStatement:69, Insert (com.baomidou.mybatisplus.core.injector.methods)
inject:59, AbstractMethod (com.baomidou.mybatisplus.core.injector)
lambda$inspectInject$0:52, AbstractSqlInjector (com.baomidou.mybatisplus.core.injector)
accept:-1, 451486961 (com.baomidou.mybatisplus.core.injector.AbstractSqlInjector$$Lambda$490)
forEach:1257, ArrayList (java.util)
inspectInject:52, AbstractSqlInjector (com.baomidou.mybatisplus.core.injector)
parse:148, MybatisMapperAnnotationBuilder (com.baomidou.mybatisplus.core)
addMapper:86, MybatisMapperRegistry (com.baomidou.mybatisplus.core)
addMapper:121, MybatisConfiguration (com.baomidou.mybatisplus.core)
bindMapperForNamespace:432, XMLMapperBuilder (org.apache.ibatis.builder.xml)
parse:97, XMLMapperBuilder (org.apache.ibatis.builder.xml)
buildSqlSessionFactory:630, MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring)
afterPropertiesSet:387, MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring)
getObject:685, MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring)
sqlSessionFactory:93, MyBatisConfiguration (com.test.core.config)
CGLIB$sqlSessionFactory$1:-1, MyBatisConfiguration$$EnhancerBySpringCGLIB$$b8579068 (com.test.core.config)
invoke:-1, MyBatisConfiguration$$EnhancerBySpringCGLIB$$b8579068$$FastClassBySpringCGLIB$$ce8d5cbe (com.test.core.config)
invokeSuper:244, MethodProxy (org.springframework.cglib.proxy)
intercept:331, ConfigurationClassEnhancer$BeanMethodInterceptor (org.springframework.context.annotation)
sqlSessionFactory:-1, MyBatisConfiguration$$EnhancerBySpringCGLIB$$b8579068 (com.test.core.config)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
instantiate:154, SimpleInstantiationStrategy (org.springframework.beans.factory.support)
instantiate:652, ConstructorResolver (org.springframework.beans.factory.support)
instantiateUsingFactoryMethod:637, ConstructorResolver (org.springframework.beans.factory.support)
instantiateUsingFactoryMethod:1341, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBeanInstance:1181, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:556, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:516, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:324, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1542598424 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$155)
getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:322, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support)
resolveCandidate:276, DependencyDescriptor (org.springframework.beans.factory.config)
doResolveDependency:1307, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveDependency:1227, DefaultListableBeanFactory (org.springframework.beans.factory.support)
autowireByType:1514, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
populateBean:1409, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:593, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:516, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:324, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1542598424 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$155)
getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:322, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support)
resolveCandidate:276, DependencyDescriptor (org.springframework.beans.factory.config)
doResolveDependency:1307, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveDependency:1227, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveFieldValue:657, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation)
inject:640, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation)
inject:119, InjectionMetadata (org.springframework.beans.factory.annotation)
postProcessProperties:399, AutowiredAnnotationBeanPostProcessor (org.springframework.beans.factory.annotation)
populateBean:1425, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:593, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:516, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:324, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1542598424 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$155)
getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:322, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support)
resolveCandidate:276, DependencyDescriptor (org.springframework.beans.factory.config)
doResolveDependency:1307, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveDependency:1227, DefaultListableBeanFactory (org.springframework.beans.factory.support)
resolveFieldValue:657, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation)
inject:640, AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement (org.springframework.beans.factory.annotation)
inject:119, InjectionMetadata (org.springframework.beans.factory.annotation)
postProcessProperties:399, AutowiredAnnotationBeanPostProcessor (org.springframework.beans.factory.annotation)
populateBean:1425, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:593, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:516, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:324, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 1542598424 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$155)
getSingleton:234, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:322, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support)
preInstantiateSingletons:897, DefaultListableBeanFactory (org.springframework.beans.factory.support)
finishBeanFactoryInitialization:879, AbstractApplicationContext (org.springframework.context.support)
refresh:551, AbstractApplicationContext (org.springframework.context.support)
refresh:143, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:755, SpringApplication (org.springframework.boot)
refresh:747, SpringApplication (org.springframework.boot)
refreshContext:402, SpringApplication (org.springframework.boot)
run:312, SpringApplication (org.springframework.boot)
run:1247, SpringApplication (org.springframework.boot)
run:1236, SpringApplication (org.springframework.boot)
main:20, JobApplication (com.test)

你可能感兴趣的:(java)