Closed archerForzmy closed 4 years ago
不知什么原因这个方法获取dubbo远程服务的bean name就会有乱码,获取本地服务bean name就正常
你使用什么存储的? 存储的编码方式是什么?
@yu199195 db方式 utf-8编码
@yu199195 用的是dubbo方式,断点到SpringBeanUtils的getByName方法时获取的类名都是正确的没有乱码但是走完bean = cfgContext.getBean(firstLowercase(firstDelete(className)), type);
语句以后bean name就乱码了
bean = cfgContext.getBean(firstLowercase(firstDelete(className)), type); 这句代码在哪里
org.dromara.hmily.core.helper.SpringBeanUtils
顺便说一句我试了zk,redis,db都不好使一样的异常
我把断点截图给你,你这段代码我实在没看懂要干嘛
我也忘记了,你的service是怎么命名的。看下demo
我的service命名和你demo中命名是一样的首字母小写驼峰命名,你这段代码明细逻辑有问题啊,首先获取到接口名AccountService正常情况下要得到accountService作为bean name,但是你上面的逻辑将接口名的首字母去掉,然后在将剩余的字符串首字符+32,明显得到的会是乱码,我给你的截图中c+32必定是乱码,我猜你原本是c-32=C对吧。
在说一句 AccountService在你的demo里面是作为提供者在OrderService中,奇怪的是OrderService可以正常转成orderService,AccountService就转成了countService明显不正常,导致Order成功confirm了,剩下两个都是处在try完成状态无法confirm,当定时任务扫描到try超时就会自动cancel结果就是订单成功了,没有扣费,没有减库存
public
@yu199195
bean = cfgContext.getBean(type);
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.common.service.AccountService' available
我照你的demo搭了一个项目,这一般是什么原因导致的
@yu199195 你的这个框架兼容了下面这个依赖吗
`
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.1.RELEASE</version>
</dependency>`
如果消费方使用@Reference注入就会出现上面的异常,使用xml方式这个demo就走通了
public T getBean(final Class type) { AssertUtils.notNull(type); T bean; try { bean = cfgContext.getBean(type); } catch (BeansException e) { bean = getByName(type); } return bean; } 1.为什么上面会异常? 然后再去getByName?
- 你是运行的demo ,有这个错误?
遇到了同样的问题,原因是spring上下文中实际的bean类型是代理类,所以 cfgContext.getBean(type) 会执行异常,然后才会执行 getByName(type),
bean = cfgContext.getBean(firstLowercase(firstDelete(className)), type);
然后本人debug源码,去掉了firstDelete方法使其获取到正确的beanName之后抛出的异常印证了这点
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'feignClientController' is expected to be of type 'com.hy.feign.web.FeignClientController' but was actually of type 'com.hy.feign.web.FeignClientController$$EnhancerBySpringCGLIB$$31bc8780' at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:392) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1111) ~[spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE] at org.dromara.hmily.core.helper.SpringBeanUtils.getByName(SpringBeanUtils.java:72) ~[hmily-core-2.0.5-HY-RELEASE.jar:2.0.5-HY-RELEASE] at org.dromara.hmily.core.helper.SpringBeanUtils.getBean(SpringBeanUtils.java:64) ~[hmily-core-2.0.5-HY-RELEASE.jar:2.0.5-HY-RELEASE] at org.dromara.hmily.core.reflect.HmilyReflector.execute(HmilyReflector.java:66) ~[hmily-core-2.0.5-HY-RELEASE.jar:2.0.5-HY-RELEASE] at org.dromara.hmily.core.reflect.HmilyReflector.executor(HmilyReflector.java:54) ~[hmily-core-2.0.5-HY-RELEASE.jar:2.0.5-HY-RELEASE] at org.dromara.hmily.core.service.recovery.HmilyTransactionRecoveryService.cancel(HmilyTransactionRecoveryService.java:69) ~[hmily-core-2.0.5-HY-RELEASE.jar:2.0.5-HY-RELEASE] at org.dromara.hmily.core.schedule.HmilyTransactionSelfRecoveryScheduled.lambda$selfRecovery$1(HmilyTransactionSelfRecoveryScheduled.java:124) [hmily-core-2.0.5-HY-RELEASE.jar:2.0.5-HY-RELEASE] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_162] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_162] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_162] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_162] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_162] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_162] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_162]
我也遇到了这个问题,解决了吗大神们
可能是因为springcloud的版本问题,导致了加载顺序问题, 可以使用2.0.6版本来解决该问题。 如果是dubbo 建议不要使用starter的方式,改用xml
今天使用了2.0.6试了,(其他的版本也试了),这个问题好像一直在,我的springcloud版本Finchley.SR1, springboot 2.1.3, 奇怪的是:官方的demo不论怎么折腾都很完美,我的项目中 bean = cfgContext.getBean这句报错,找不到 feign,或者普通的service实现类,有时要找的类中还乱码(贴到文件中,发现前几个字母替换成了STS)
可能是你的springcloud没整合对
不要使用spring devtool 这个工具,会导致类加载器改变!
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ventoryService' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:685) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1095) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.dromara.hmily.core.helper.SpringBeanUtils.getByName(SpringBeanUtils.java:72) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.helper.SpringBeanUtils.getBean(SpringBeanUtils.java:64) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.reflect.HmilyReflector.execute(HmilyReflector.java:66) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.reflect.HmilyReflector.executor(HmilyReflector.java:54) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.service.executor.HmilyTransactionExecutor.confirm(HmilyTransactionExecutor.java:149) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.service.handler.StarterHmilyTransactionHandler.lambda$handler$1(StarterHmilyTransactionHandler.java:81) [hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.disruptor.handler.HmilyConsumerTransactionDataHandler.executor(HmilyConsumerTransactionDataHandler.java:28) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.disruptor.handler.HmilyConsumerTransactionDataHandler.executor(HmilyConsumerTransactionDataHandler.java:13) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.disruptor.DisruptorConsumer.onEvent(DisruptorConsumer.java:40) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at org.dromara.hmily.core.disruptor.DisruptorConsumer.onEvent(DisruptorConsumer.java:29) ~[hmily-core-2.0.5-RELEASE.jar:2.0.5-RELEASE] at com.lmax.disruptor.WorkProcessor.run(WorkProcessor.java:143) ~[disruptor-3.4.0.jar:na] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_172]