BladeX-Boot 4.6版本使用最新的多数据源配置,不生效

Blade 未结 1 111
日行千里
日行千里 2025-08-27 15:18

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

1. 最新版的Bladex-Boot,参考blade-demo项目的多数据源配置后,多数据源不生效

2. 

3.


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

正常运行

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

BladeX-Boot 4.6.0     windows server 2026

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

org.springframework.jdbc.BadSqlGrammarException: 

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (1, 1, null, null);INSERT ' at line 1

### The error may exist in file [E:\workspace\blade-boot\target\classes\cn\test\link\mapper\RealDataMapper.xml]

### The error may involve defaultParameterMap

### The error occurred while setting parameters

### SQL: INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?);INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (?, ?, ?, ?)

### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (1, 1, null, null);INSERT ' at line 1

; bad SQL grammar []

at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:246)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:107)

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:93)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:347)

at jdk.proxy2/jdk.proxy2.$Proxy121.insert(Unknown Source)

at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:224)

at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:59)

at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:156)

at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:93)

at jdk.proxy2/jdk.proxy2.$Proxy131.saveRealData(Unknown Source)

at cn.aerotop.link.service.impl.RealDataServiceImpl.saveRealData(RealDataServiceImpl.java:18)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)

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

at cn.aerotop.link.service.impl.RealDataServiceImpl$$SpringCGLIB$$0.saveRealData()

at cn.aerotop.link.listener.ValueListener.alarm(ValueListener.java:63)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)

at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)

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

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

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

at cn.aerotop.core.log.aspect.LogTraceAspect.around(LogTraceAspect.java:20)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

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

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

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

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

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

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

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

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

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

at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)

at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)

at cn.aerotop.core.context.BdpRunnableWrapper.run(BdpRunnableWrapper.java:33)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)

at java.base/java.lang.Thread.run(Thread.java:842)

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO realdata (sid, pid, pvalue, ptime) VALUES (1, 1, null, null);INSERT ' at line 1

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:912)

at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:354)

at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3462)

at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:434)

at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3460)

at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:434)

at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3460)

at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:158)

at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:483)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:48)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:75)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)

at jdk.proxy2/jdk.proxy2.$Proxy229.update(Unknown Source)

at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)

at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)

at jdk.internal.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:61)

at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:106)

at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:59)

at jdk.proxy2/jdk.proxy2.$Proxy228.update(Unknown Source)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)

at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:333)

... 44 common frames omitted

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

多数据源配置文件:

spring:

  datasource:

    url: jdbc:mysql://127.0.0.1:3306/iot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true

    username: root

    password: 12345678

    driver-class-name: com.mysql.cj.jdbc.Driver

    dynamic:

      druid:

        #通用校验配置

        validation-query: select 1

      primary: master

      datasource:

        slave:

          druid:

            #独立校验配置

            validation-query: select 1

          url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=scada;encrypt=true;trustServerCertificate=true

          username: sa

          password: 12345678

          driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver



项目pom.xml配置

 

          org.springblade

         blade-starter-db-dynamic


实现类

@Service

@DS("slave")

public class RealDataServiceImpl extends ServiceImpl implements RealDataService {


    @DS("slave")

    public int saveRealData(List dataList) {

        return baseMapper.saveRealData(dataList);

    }

}


调用

@Component

public class ValueListener {



    @Autowired

    private RealDataService dataService;


    @Async

    @EventListener(condition = "#event.type=='META_EVENT'")

    public void alarm(ParseEvent event) {

         MetaData data=(MetaData)event.getMessage();

         if(Func.isEmpty(data)) {

              return;

         }

         DataForward metaData=this.buildMetaData(data);

         dataService.saveRealData(metaData.getRealDataList());

    }

}

1条回答
提交回复