mysql+clickhouse多数据源下,一操作数据库就疯狂报错

Blade 未结 1 173

一、该问题的重现步骤是什么?

1. 配置了 mysql + clickhouse

2. 使用 @DS 来切换数据源(mysql是主,切到clickhouse)

3. 为了实现 @DS 注解实现了 


DataSourceConfig

DS

DynamicDataSource

DynamicDataSourceAspect

DynamicDataSourceContextHolder


二、你期待的结果是什么?实际看到的又是什么?

期待能正常访问 clickhouse。                   现在访问 mysql 和 clickhouse 报相同的错误


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladex,Windows


四、请提供详细的错误堆栈信息,这很重要。

2024-08-30 16:19:51.513 ERROR 17604 --- [   async-task-7] o.s.c.b.c.BladeExecutorConfiguration     : Unexpected exception occurred invoking async method: public void org.springblade.common.event.ErrorLogListener.saveErrorLog(org.springblade.core.log.event.ErrorLogEvent)


org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): org.springblade.modules.system.mapper.LogErrorMapper.insert

at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:229)

at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)

at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:96)

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)

at org.apache.ibatis.util.MapUtil.computeIfAbsent(MapUtil.java:36)

at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:94)

at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)

at com.sun.proxy.$Proxy197.insert(Unknown Source)

at com.baomidou.mybatisplus.extension.service.IService.save(IService.java:60)

at com.baomidou.mybatisplus.extension.service.IService$$FastClassBySpringCGLIB$$f8525d18.invoke(<generated>)

at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386)

at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85)

at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:703)

at org.springblade.modules.system.service.impl.LogErrorServiceImpl$$EnhancerBySpringCGLIB$$424a4089.save(<generated>)

at org.springblade.modules.system.service.impl.LogServiceImpl.saveErrorLog(LogServiceImpl.java:38)

at org.springblade.common.event.ErrorLogListener.saveErrorLog(ErrorLogListener.java:55)

at org.springblade.common.event.ErrorLogListener$$FastClassBySpringCGLIB$$d15d923a.invoke(<generated>)

at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:792)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)

at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)

at org.springblade.core.log.aspect.LogTraceAspect.around(LogTraceAspect.java:41)

at sun.reflect.GeneratedMethodAccessor52.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634)

at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624)

at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)

at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)

at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at org.springblade.core.context.BladeRunnableWrapper.run(BladeRunnableWrapper.java:54)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)


五、若有更多详细信息,请在下面提供。

org.springblade.job.controller;

org.apache.ibatis.session.SqlSessionFactory;
org.mybatis.spring.SqlSessionFactoryBean;
org.mybatis.spring.annotation.;
org.springframework.beans.factory.annotation.;
org.springframework.boot.context.properties.;
org.springframework.boot.jdbc.DataSourceBuilder;
org.springframework.context.annotation.;
org.springframework.context.annotation.;
org.springframework.context.annotation.;
org.springframework.core.io.support.PathMatchingResourcePatternResolver;
org.springframework.jdbc.core.JdbcTemplate;
org.springframework.jdbc.datasource.DataSourceTransactionManager;

javax.sql.DataSource;

(basePackages = , sqlSessionFactoryRef = )
DataSourceConfig {

    (name = )
    (prefix = )
    DataSource () {
        DataSourceBuilder.().build();
    }

    (name = )
    (prefix = )
    DataSource () {
        DataSourceBuilder.().build();
    }

    (name = )
    SqlSessionFactory (() DataSource dataSource) Exception {
        SqlSessionFactoryBean sessionFactory = SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setMapperLocations(PathMatchingResourcePatternResolver().getResources());
        sessionFactory.getObject();
    }

    (name = )
    DataSourceTransactionManager (() DataSource dataSource) {
        DataSourceTransactionManager(dataSource);
    }

    (name = )
    SqlSessionFactory (() DataSource dataSource) Exception {
       SqlSessionFactoryBean sessionFactory = SqlSessionFactoryBean();
       sessionFactory.setDataSource(dataSource);
       sessionFactory.setMapperLocations(PathMatchingResourcePatternResolver().getResources());
       sessionFactory.getObject();
    }

    (name = )
    DataSourceTransactionManager (() DataSource dataSource) {
       DataSourceTransactionManager(dataSource);
    }

    (name = )
    JdbcTemplate (() DataSource dataSource) {
       JdbcTemplate(dataSource);
    }

    (name = )
    JdbcTemplate (() DataSource dataSource) {
       JdbcTemplate(dataSource);
    }


}
org.springblade.job.controller;
java.lang.annotation.*;

({ElementType., ElementType.})
(RetentionPolicy.)
@{
    String () ; }
org.springblade.job.controller;

org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

DynamicDataSource AbstractRoutingDataSource {

    ThreadLocal<String> = ThreadLocal<>();

    (String dataSourceType) {
        .set(dataSourceType);
    }

    String () {
        .get();
    }

    () {
        .remove();
    }

    Object () {
        ();
    }
}
org.springblade.job.controller;

org.aspectj.lang.JoinPoint;
org.aspectj.lang.annotation.;
org.aspectj.lang.annotation.;
org.aspectj.lang.annotation.;
org.springframework.stereotype.;

DynamicDataSourceAspect {

    ()
    (JoinPoint point, ds) {
        DynamicDataSourceContextHolder.(ds.value());
    }

    ()
    (JoinPoint point, ds) {
        DynamicDataSourceContextHolder.();
    }
}
org.springblade.job.controller;

DynamicDataSourceContextHolder {

    (String dataSourceType) {
        DynamicDataSource.(dataSourceType);
    }

    String () {
        DynamicDataSource.();
    }

    () {
        DynamicDataSource.();
    }
}


1条回答
提交回复