```
package com.polysoft.ins.common.config;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
public class SelectAll extends AbstractMethod {
@Override
public MappedStatement injectMappedStatement(Class> mapperClass, Class> modelClass, TableInfo tableInfo) {
/* 执行 SQL ,动态 SQL 参考类 SqlMethod */
String sql = "select * from " + tableInfo.getTableName();
/* mapper 接口方法名一致 */
String method = "selectAll";
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
return this.addSelectMappedStatement(mapperClass, method, sqlSource, modelClass, tableInfo);
}
}
```
```
package com.polysoft.ins.common.config;
import java.util.List;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
@Component
public class MySqlInjector extends DefaultSqlInjector {
@Override
public List getMethodList() {
List methodList = super.getMethodList();
//增加自定义方法
methodList.add(new SelectAll());
return methodList;
}
}
```
```
public interface InsBaseMapper extends BaseMapper{
List selectAll();
}
```
报错信息如下
```
2018-09-07 18:45:16.782 WARN [ins-user,,,] 74245 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'channelController': Unsatisfied dependency expressed through field 'channelService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'channelService': Unsatisfied dependency expressed through field 'channelMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'channelMapper' defined in file [/Users/apple/Desktop/huayun/ins-user/target/classes/com/polysoft/ins/user/mapper/ChannelMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.baomidou.mybatisplus.core.injector.ISqlInjector' available: expected single matching bean but found 3: mySqlInjector,myLogicSqlInjector,sqlInjector
2018-09-07 18:45:16.805 INFO [ins-user,,,] 74245 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed
2018-09-07 18:45:17.639 INFO [ins-user,,,] 74245 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-09-07 18:45:17.644 WARN [ins-user,,,] 74245 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [RxIoScheduler-1 (Evictor)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
2018-09-07 18:45:17.666 INFO [ins-user,,,] 74245 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-07 18:45:17.673 ERROR [ins-user,,,] 74245 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
file [/Users/apple/Desktop/huayun/ins-user/target/classes/com/polysoft/ins/user/mapper/ChannelMapper.class] required a single bean, but 3 were found:
- mySqlInjector: defined in file [/Users/apple/Desktop/huayun/ins-common/target/classes/com/polysoft/ins/common/config/MySqlInjector.class]
- myLogicSqlInjector: defined by method 'myLogicSqlInjector' in class path resource [com/polysoft/ins/common/config/MyBatisPlusConfig.class]
- sqlInjector: defined by method 'sqlInjector' in class path resource [com/polysoft/ins/common/config/MyBatisPlusConfig.class]
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
```