1 找不到包:SeataDataSourceBeanPostProcessor
java.lang.IllegalStateException: Error processing condition on io.seata.spring.boot.autoconfigure.SeataAutoConfiguration.globalTransactionScanner
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at cn.yufeng.sindar.app.SindarApplication.main(SindarApplication.java:25)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [io.seata.spring.boot.autoconfigure.SeataAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:743)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:742)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:681)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:649)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1605)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:520)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:491)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:230)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:223)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:213)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:167)
at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:142)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
... 15 common frames omitted
Caused by: java.lang.NoClassDefFoundError: io/seata/spring/annotation/datasource/SeataDataSourceBeanPostProcessor
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 31 common frames omitted
Caused by: java.lang.ClassNotFoundException: io.seata.spring.annotation.datasource.SeataDataSourceBeanPostProcessor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 35 common frames omitted
1.1 问题原因:
seata 版本问题, spring-cloud-alibaba 依赖下的seata-spring-boot-starter 版本是1.1.0,而我用的seata是 1.3.0 版本 。
1.3.0 版本SeataAutoConfiguration.class 没有seataDataSourceBeanPostProcessor bean ,而是用SeataAutoDataSourceProxyCreator代替。
1.3.0 版本
@Bean(BEAN_NAME_SEATA_AUTO_DATA_SOURCE_PROXY_CREATOR)
@ConditionalOnProperty(prefix = StarterConstants.SEATA_PREFIX, name = {"enableAutoDataSourceProxy", "enable-auto-data-source-proxy"}, havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(SeataAutoDataSourceProxyCreator.class)
public SeataAutoDataSourceProxyCreator seataAutoDataSourceProxyCreator(SeataProperties seataProperties) {
return new SeataAutoDataSourceProxyCreator(seataProperties.isUseJdkProxy(),
seataProperties.getExcludesForAutoProxying(), seataProperties.getDataSourceProxyMode());
}
1.2 解决方案:
去掉spring-cloud-starter-alibaba-seata 下seata-spring-boot-starter 依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<exclusion>
<artifactId>seata-all</artifactId>
<groupId>io.seata</groupId>
</exclusion>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>${spring-alibaba-seata.version}</version>
<exclusions>
<exclusion>
<artifactId>fastjson</artifactId>
<groupId>com.alibaba</groupId>
</exclusion>
</exclusions>
</dependency>
2 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service ‘null’ found, please make sure registry config correct。没有找到服务,请确认注册表是否正确。
2020-09-02 17:56:11.088 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:11.122 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:21.086 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:21.121 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:31.087 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:31.122 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:32.738 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-02 17:56:39.604 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-02 17:56:41.089 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:41.122 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:51.087 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:56:51.124 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:57:01.088 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
2020-09-02 17:57:01.123 [ERROR] i.s.c.r.n.NettyClientChannelManager - no available service 'null' found, please make sure registry config correct
而且是不停的打印错误信息。
2.1 问题原因:
tx-service-group: my_test_tx_group 与配置的不统一。
2.2 解决方案:
seata:
enabled: true
application-id: ${spring.application.name}
tx-service-group: my_test_tx_group # tx-service-group 的value值 要与下面的vgroupMapping 的key 值对应。
enable-auto-data-source-proxy: false
registry:
type: nacos
nacos:
server-addr: http://localhost:8848
group: SEATA_GROUP
namespace: seata
username: nacos
password: nacos
service:
grouplist:
default: localhost:8091
disable-global-transaction: false
vgroupMapping:
my_test_tx_group: default
config:
type: nacos
nacos:
server-addr: http://localhost:8848
group: SEATA_GROUP
namespace: seata
username: nacos
password: nacos
3 [ERROR] i.s.r.d.e.AbstractDMLBaseExecutor - execute executeAutoCommitTrue error:io.seata.core.exception.RmTransactionException: Runtime
2020-09-02 19:03:00.633 [ERROR] i.s.r.d.e.AbstractDMLBaseExecutor - execute executeAutoCommitTrue error:io.seata.core.exception.RmTransactionException: Runtime
java.sql.SQLException: io.seata.core.exception.RmTransactionException: Runtime
at io.seata.rm.datasource.ConnectionProxy.recognizeLockKeyConflictException(ConnectionProxy.java:157)
at io.seata.rm.datasource.ConnectionProxy.processGlobalTransactionCommit(ConnectionProxy.java:218)
at io.seata.rm.datasource.ConnectionProxy.doCommit(ConnectionProxy.java:196)
at io.seata.rm.datasource.ConnectionProxy.lambda$commit$0(ConnectionProxy.java:184)
at io.seata.rm.datasource.ConnectionProxy$LockRetryPolicy.execute(ConnectionProxy.java:289)
at io.seata.rm.datasource.ConnectionProxy.commit(ConnectionProxy.java:183)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.lambda$executeAutoCommitTrue$0(AbstractDMLBaseExecutor.java:112)
at io.seata.rm.datasource.ConnectionProxy$LockRetryPolicy.doRetryOnLockConflict(ConnectionProxy.java:299)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor$LockRetryPolicy.execute(AbstractDMLBaseExecutor.java:155)
at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.executeAutoCommitTrue(AbstractDMLBaseExecutor.java:110)
.
.
.
2020-09-02 19:12:23.119 [WARN ] c.a.c.s.w.SeataHandlerInterceptor - xid in change during RPC from localhost:8091:44501318076755968 to null
2020-09-02 19:12:23.120 [ERROR] o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/sindar-crs] threw exception [Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: io.seata.core.exception.RmTransactionException: Runtime
### The error may involve cn.yufeng.sindar.dao.mapper.OrderMapper.insertSelective-Inline
### The error occurred while setting parameters
3.1 问题原因:
同2.1
3.2 解决方案:
同2.1 或在nacos 配置中心添加 vgroupMapping.order_tx_group
4 io.seata.common.exception.ShouldNeverHappenException: Can’t find any object of class org.springframework.context.ApplicationContext 找不到 ApplicationContext 类。
4.1 问题原因:
基本上看到 io.seata.common.exception.ShouldNeverHappenException 这个异常都是版本问题。我的是因为父工程springcloud 是Hoxton.SR3版本 子工程是Hoxton.Release版。
4.2 解决方案:
统一父子工程spring cloud 版本。
5 Method nacosWatch in com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration required a single bean, but 2 were found
Method nacosWatch in com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration required a single bean, but 2 were found:
- defaultSockJsTaskScheduler: defined by method 'defaultSockJsTaskScheduler' in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.class]
- messageBrokerTaskScheduler: defined by method 'messageBrokerTaskScheduler' in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]
哎,没完了。nacos 又有问题了。
5.1 问题原因:
是因为项目中引用了, websocket jar包。 websocket 定时任务下有两个实例 defaultSockJsTaskScheduler和messageBrokerTaskSchedul。不清楚NacosDiscoveryClientConfiguration 为什么要注入的是单例。导致出异常,websocket 不能与nacos 兼容,这应该是nacos 的一个bug。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
5.2 解决方案
去掉spring-boot-starter-websocket 包
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>-->
6 mybatis 绑定返回对象出错。
2020-09-03 14:25:31.519 [ERROR] o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/sindar] threw exception
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): XXX.dao.mapper.mbg.XXXMapper.queryAllList
6.1 问题原因:
代理数据源找不到mapper.xml 文件
6.2 解决方案
在SqlSessionFactory bean里加入classpath mapper路径
@Configuration
@EnableTransactionManagement
@MapperScan({"cn.test.user.dao.mapper"})
public class DataSourceProxyConfig {
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return new DruidDataSource();
}
@Bean
public DataSourceProxy dataSourceProxy(@Qualifier("dataSource") DataSource dataSource) {
return new DataSourceProxy(dataSource);
}
@Bean
public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSourceProxy);
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources("classpath*:dao/mapper/*.xml"));
return sqlSessionFactoryBean.getObject();
}
@Bean
public PageHelper pageHelper() {
System.out.println("MyBatisConfiguration.pageHelper()");
PageHelper pageHelper = new PageHelper();
Properties p = new Properties();
p.setProperty("offsetAsPageNum", "true");
p.setProperty("rowBoundsWithCount", "true");
p.setProperty("reasonable", "true");
pageHelper.setProperties(p);
return pageHelper;
}
7 控制台不停打印nacos 日志
c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 13:59:26.588 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 13:59:49.613 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 13:59:56.092 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:00:19.117 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:00:25.596 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:00:48.620 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:00:55.100 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:01:18.124 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:01:24.603 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:01:47.628 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:01:54.107 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:02:17.132 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:02:23.611 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:02:46.637 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
2020-09-07 14:02:53.115 [INFO ] c.a.n.c.c.i.ClientWorker - get changedGroupKeys:[]
7.1、 nacos 配置文件
配置文件内容md5与服务器上的md5 不一致。
7.2、在yaml 配置里设置nacos 日志等级
spring:
version: 1.0.1
profiles:
active: dev
logging:
config: classpath:log/logback-spring.xml
level:
com.alibaba.nacos.client.*: WARN