当你途径我的盛放 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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能