当你途径我的盛放 2018-11-07 10:53 采纳率: 55.6%
浏览 2568

springboot gradle mybatis MapperScan.factoryBean()异常

异常

 Caused by: java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean()
    at java.lang.reflect.Method.getDefaultValue(Method.java:612) ~[na:1.8.0_131]
    at org.springframework.core.annotation.AnnotationUtils.registerDefaultValues(AnnotationUtils.java:1258) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]

配置:

 @Configuration
@MapperScan(basePackages = EntMasterDataSourceConfig.BASE_PACKAGE, sqlSessionFactoryRef = "entMasterSqlSessionFactory")
public class EntMasterDataSourceConfig {
    static final String BASE_PACKAGE = "com.sunlands.entmaster";
    static final String MAPPER_LOCATION = "classpath:/*.xml";

    @Value("${spring.datasource.ent_master.url}")
    private String dbUrl;
    @Value("${spring.datasource.ent_master.username}")
    private String dbUser;
    @Value("${spring.datasource.ent_master.password}")
    private String dbPassword;
    @Value("${spring.datasource.driver-class-name}")
    private String dbDriver;


    /**
     * 配置数据数据源 master
     *
     * @return
     */
    @Bean(name = "entMasterDatasource")
    @Primary
    public DataSource masterDatasource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(dbDriver);
        dataSource.setUrl(dbUrl);
        dataSource.setUsername(dbUser);
        dataSource.setPassword(dbPassword);
        //连接池启动时创建的初始化连接数量
        dataSource.setInitialSize(1);
        //连接池中可同时连接的最大的连接数
        dataSource.setMaxActive(100);
        //连接池中最小的空闲的连接数,低于这个数量会被创建新的连接
        dataSource.setMinIdle(5);
        //最大等待时间,当没有可用连接时,连接池等待连接释放的最大时间,超过该时间限制会抛出异常,如果设置-1表示无限等待
        dataSource.setMaxWait(60000);
        //超过removeAbandonedTimeout时间后,是否进 行没用连接(废弃)的回收(默认为false,调整为true)
        dataSource.setRemoveAbandoned(true);
        //超过时间限制,回收没有用(废弃)的连接(默认为 300秒,调整为180)
        dataSource.setRemoveAbandonedTimeout(180);
        //默认提交
        dataSource.setDefaultAutoCommit(true);
        //打开检查,用异步线程evict进行检查
        dataSource.setTestWhileIdle(true);
        //就是在进行borrowObject进行处理时,对拿到的connection进行validateObject校验
        dataSource.setTestOnBorrow(false);
        //就是在进行returnObject对返回的connection进行validateObject校验,个人觉得对数据库连接池的管理意义不大
        dataSource.setTestOnReturn(false);
        // 代表检查的sql
        dataSource.setValidationQuery("select 1 from dual");
        //代表在执行检查时,通过statement设置,statement.setQueryTimeout(validationQueryTimeout)
        dataSource.setValidationQueryTimeout(1);
        dataSource.setTimeBetweenEvictionRunsMillis(30000);
        return dataSource;
    }

    /**
     * 配置session工厂
     *
     * @param entMasterDatasource
     * @return
     * @throws Exception
     */
    @Bean(name = "entMasterSqlSessionFactory")
    @Primary
    public SqlSessionFactory masterSqlSessionFactory(@Qualifier("entMasterDatasource") DataSource entMasterDatasource) throws Exception {
        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(entMasterDatasource);
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources(EntMasterDataSourceConfig.MAPPER_LOCATION));
        return sessionFactory.getObject();
    }


    /**
     * 配置事务管理器
     *
     * @param dataSource
     * @return
     */
    @Bean(name = "entMasterTransactionManger")
    @Primary
    public DataSourceTransactionManager masterTransactionManger(@Qualifier("entMasterDatasource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }


}

gradle springboot是2.1.0

 dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testImplementation('org.springframework.boot:spring-boot-starter-test')

    compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '2.1.0.RELEASE'
    compile group: 'com.alibaba', name: 'fastjson', version: '1.2.51'
    compile group: 'com.alibaba', name: 'druid', version: '1.1.12'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.1.0.RELEASE'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
    compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.34'
    compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '1.3.2'
    compile group: 'org.mybatis', name: 'mybatis-spring', version: '1.3.2'
    compile group: 'org.springframework', name: 'spring-jdbc', version: '5.1.2.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '5.1.2.RELEASE'
    compile group: 'org.mybatis', name: 'mybatis', version: '3.4.6'
}
  • 写回答

1条回答

  • devmiao 2018-11-07 11:19
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器