项目启动报错信息
Caused by: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasourceat com.baomidou.dynamic.datasource.DynamicRoutingDataSource.determinePrimaryDataSource(DynamicRoutingDataSource.java:91)at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.getDataSource(DynamicRoutingDataSource.java:120)at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.determineDataSource(DynamicRoutingDataSource.java:78)at com.baomidou.dynamic.datasource.ds.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:48)at com.baomidou.dynamic.datasource.ds.AbstractRoutingDataSource$$FastClassBySpringCGLIB$$dffddd61.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)at io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyAdvice.invoke(SeataAutoDataSourceProxyAdvice.java:57)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)at com.baomidou.dynamic.datasource.DynamicRoutingDataSource$$EnhancerBySpringCGLIB$$606bf0df.getConnection(<generated>)at io.seata.rm.datasource.DataSourceProxy.init(DataSourceProxy.java:101)at io.seata.rm.datasource.DataSourceProxy.<init>(DataSourceProxy.java:96)at io.seata.rm.datasource.DataSourceProxy.<init>(DataSourceProxy.java:81)at io.seata.spring.annotation.datasource.DataSourceProxyHolder.createDsProxyByMode(DataSourceProxyHolder.java:97)at io.seata.spring.annotation.datasource.DataSourceProxyHolder.putDataSource(DataSourceProxyHolder.java:88)at io.seata.spring.annotation.datasource.SeataDataSourceBeanPostProcessor.postProcessAfterInitialization(SeataDataSourceBeanPostProcessor.java:58)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)... 100 common frames omitted
报错原因分析
1.可能是引入了多数据源又没有使用,导致的报错
解决方案
注释掉上边两个依赖
<!-- Druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>${druid.version}</version></dependency><!-- Dynamic DataSource --><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>${dynamic-ds.version}</version></dependency>
2.我的项目中使用了多数据源,所以这种解决方式不可行
查看maven的配制文件,看是否加载了配制信息
看这块是否选择了正确的环境。
3.我的项目中使用的是本地环境,也就是local,然后我就去跟了下代码
发现这里报错500,报错信息为:config data not exist。
说明没有获取到nacos上的配制文件,我又去检查了下pom.xml文件。
查看后发现本地环境上配置的nacosNamespace不对,更改之后启动成功。