Comments (27)
打开debug日志, 搜索ready to analysis primarySource
日志看下, 然后debug看下 ApplicationEventTimeTable类中primarySources变量的值是什么
from dingtalk-spring-boot-starter.
@AnswerAIL
这是打印的日志
com.jaemon.dingtalk.listeners.DingerXmlPreparedEvent[DingerXmlPreparedEvent.java:85] ready to analysis primarySource[org.springframework.cloud.bootstrap.BootstrapImportSelectorConfiguration].
primarySources里面只有一个,值是:
class org.springframework.cloud.bootstrap.BootstrapImportSelectorConfiguration
from dingtalk-spring-boot-starter.
StartEventListener执行了两次,两次ApplicationEventTimeTable.primarySources的赋值分别是:
第一次(我们项目的Application):
class com.XXXX.Application
第二次:
class org.springframework.cloud.bootstrap.BootstrapImportSelectorConfiguration
from dingtalk-spring-boot-starter.
请拉取最新测试版本 2.0.3-beta1.jar 进行验证, 谢谢!
无法拉取最新版本, 请手动下载 dingtalk-spring-boot-starter-2.0.3-beta1.jar ,并在maven中使用本地引入方式
from dingtalk-spring-boot-starter.
手动引入2.0.3-beta1.jar以后启动提示另外一个错误:
No qualifying bean of type 'com.jaemon.dingtalk.entity.DingTalkProperties' available
debug发现jar包中spring.factories的ApplicationListener配置都已执行
org.springframework.context.ApplicationListener=\
com.jaemon.dingtalk.listeners.StartEventListener,\
com.jaemon.dingtalk.listeners.SuccessEventListener,\
com.jaemon.dingtalk.listeners.FailedEventListener,\
com.jaemon.dingtalk.listeners.ExitEventListener,\
com.jaemon.dingtalk.listeners.DingerXmlPreparedEvent
并在DingerXmlPreparedEvent中可以看到配置信息都可以获取到
错误发生在SuccessEventListener中的28行:
DingTalkProperties properties = (DingTalkProperties)applicationContext.getBean(DingTalkProperties.class);
from dingtalk-spring-boot-starter.
SuccessEventListener debug中查看 applicationContext.getBeanDefinitionNames()的值都有什么
from dingtalk-spring-boot-starter.
applicationContext.getBeanDefinitionNames()获取的值如图
SuccessEventListener执行了三次,在第一次执行时报错,我在第一次getBean方法体中通过debug 创建了一个DingTalkProperties对象,这样可以继续正常启动,并且SuccessEventListener执行了第二次和第三次。
第一次debug截图:
执行时,event、event.context、event.source.primarySources[0]分别是:
event:
org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication@6d9f7a80]
event.context:
org.springframework.context.annotation.AnnotationConfigApplicationContext@1a411233, started on Thu Oct 15 12:12:55 CST 2020
event.source.primarySources[0]
class org.springframework.cloud.bootstrap.BootstrapImportSelectorConfiguration
第二次debug截图:
执行时,event、event.context、event.source.primarySources[0]、event.source.primarySources[1]分别是:
event
org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication@614ca7df]
event.context
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2d82408, started on Thu Oct 15 12:15:06 CST 2020, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1a411233
event.source.primarySources[0]:
class com.XXXX.Application
event.source.primarySources[1]:
class org.springframework.cloud.bootstrap.BootstrapApplicationListener$BootstrapMarkerConfiguration
第三次debug截图:
执行时,event、event.context、event.source.primarySources[0]、event.source.primarySources[1]分别是:
event
org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication@614ca7df]
event.context
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2d82408, started on Thu Oct 15 12:15:06 CST 2020, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1a411233
event.source.primarySources[0]:
class com.XXXX.Application
event.source.primarySources[1]:
class org.springframework.cloud.bootstrap.BootstrapApplicationListener$BootstrapMarkerConfiguration
从截图中可以看到,第一次没有获取,只有我创建的那个对象。而第二次和第三次可以正常获取到了properties对象,并且属性内容是配置文件中的
from dingtalk-spring-boot-starter.
@AnswerAIL
如果在SuccessEventListener中对applicationContext的parent进行判空,对parent为空的不执行业务处理是否可以解决此问题?
from dingtalk-spring-boot-starter.
请下载2.0.3-beta2进行验证
from dingtalk-spring-boot-starter.
@AnswerAIL
如果在SuccessEventListener中对applicationContext的parent进行判空,对parent为空的不执行业务处理是否可以解决此问题?
你可以拉下源码在本地验证下
from dingtalk-spring-boot-starter.
已使用2.0.3-beta2验证,正常启动项目可以使用,如果使用junit测试就又出现了URI is not hierarchical,错误信息如下:
java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.<init>(File.java:418)
at com.jaemon.dingtalk.utils.PackageUtils.forClassNames(PackageUtils.java:97)
at com.jaemon.dingtalk.utils.PackageUtils.classNames(PackageUtils.java:73)
at com.jaemon.dingtalk.dinger.spring.DingerScannerRegistrar.registerBeanDefinitions(DingerScannerRegistrar.java:73)
at org.springframework.context.annotation.ImportBeanDefinitionRegistrar.registerBeanDefinitions(ImportBeanDefinitionRegistrar.java:86)
测试类:
下面是debug的截图:
DingerScannerRegistrar类:
最后出现上面的异常信息
from dingtalk-spring-boot-starter.
请用dingtalk-spring-boot-starter-2.0.3-beta3.jar版本进行验证,谢谢
from dingtalk-spring-boot-starter.
使用junit测试提示两个异常信息
第一个异常信息:
java.lang.IllegalStateException: org.springframework.web.context.support.GenericWebApplicationContext@4ed4a7e4 has not been refreshed yet
at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1096)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1126)
at com.jaemon.dingtalk.listeners.FailedEventListener.onApplicationEvent(FailedEventListener.java:48)
at com.jaemon.dingtalk.listeners.FailedEventListener.onApplicationEvent(FailedEventListener.java:38)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:158)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.failed(EventPublishingRunListener.java:124)
at org.springframework.boot.SpringApplicationRunListeners.callFailedListener(SpringApplicationRunListeners.java:90)
at org.springframework.boot.SpringApplicationRunListeners.failed(SpringApplicationRunListeners.java:83)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:797)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:325)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:124)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)
at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:98)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassBasedTestDescriptor.java:337)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:342)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:337)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:336)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:259)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$2(ClassBasedTestDescriptor.java:252)
at java.util.Optional.orElseGet(Optional.java:267)
at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$3(ClassBasedTestDescriptor.java:251)
at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:29)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:106)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:105)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:69)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:107)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:107)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:75)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
第二个异常信息:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.jaemon.dingtalk.entity.DingTalkProperties' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1127)
at com.jaemon.dingtalk.listeners.ExitEventListener.onApplicationEvent(ExitEventListener.java:44)
at com.jaemon.dingtalk.listeners.ExitEventListener.onApplicationEvent(ExitEventListener.java:38)
第二个异常时applicationContext中beanNames的截图
from dingtalk-spring-boot-starter.
我使用的TestController的代码:
在使用正常启动项目时,没有问题。如果使用junit,上面的RechargeDinger对象找不到,下面是junit的一条日志信息
Error creating bean with name 'testController': Unsatisfied dependency expressed through field 'rechargeDinger'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.XXX.RechargeDinger' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
这个错误导致了启动失败,然后就出现了上一条回复的异常信息,一个FailedEventListener的,一个是ExitEventListener的
from dingtalk-spring-boot-starter.
如果使用junit是什么意思? 是在junit里调用这个controller里的ding接口还是?junit里具体调用代码是?
from dingtalk-spring-boot-starter.
两种测试方法:
第一种:通过@SpringBootTest进行测试,直接调用RechargeDinger进行发送消息,下面是Test类的代码
第二种:正常启动项目,通过访问controller的url,调用RechargeDinger进行了发送消息,下面是Controller的代码
第二种方法没有问题
第一种运行@SpringBootTest对应的@test方法就不行,会报错,提示:
No qualifying bean of type 'com.XXX.RechargeDinger' available
from dingtalk-spring-boot-starter.
你启动类的代码发我看下
from dingtalk-spring-boot-starter.
@SpringBootApplication
@MapperScan("com.XXX.mapper")
@DingerScan(basePackages = "com.XXX.components.dinger")
@EnableSwaggerBootstrapUI
@EnableDiscoveryClient
@EnableXXXFeignClients
@EnableXXXHttpFeignInterceptor
public class PlatformProviderTradeApplication {
public static void main(String[] args) {
SpringApplication.run(PlatformProviderTradeApplication.class, args);
}
}
from dingtalk-spring-boot-starter.
'com.XXX.RechargeDinger'这个类的包路径是com.XXX.components.dinger这个嘛
from dingtalk-spring-boot-starter.
@AnswerAIL
Dinger接口都在这个包里面
from dingtalk-spring-boot-starter.
debug看下ApplicationEventTimeTable emptyDingerClasses方法dingerClasses的值是多少
from dingtalk-spring-boot-starter.
这个类位于test下面
from dingtalk-spring-boot-starter.
这个不能测试用例类不能放在和dingerscan指定包相同的包下,你改下测试类的包名看下
from dingtalk-spring-boot-starter.
修改test下的包名以后可以正常运行了,麻烦发布个RELEASE包到maven库吧,感谢感谢!!!
from dingtalk-spring-boot-starter.
com.XXX.components.dinger.RechargeDingerTest
com.XXX.components.dinger.RechargeDinger
改成
com.XXX.components.dingertest.RechargeDingerTest
试下,后面版本我优化下这些问题
from dingtalk-spring-boot-starter.
dingtalk-spring-boot-starter-2.0.3-beta3.jar
这个版本已经发布到maven,可以直接用,2.0.4版本周末发布
from dingtalk-spring-boot-starter.
dingtalk-spring-boot-starter-2.0.3-beta3.jar
这个版本已经发布到maven,可以直接用,2.0.4版本周末发布
好的,感谢~~~
from dingtalk-spring-boot-starter.
Related Issues (20)
- springboot工程打包后在CentOS上无法使用 HOT 3
- 支持接收群聊消息吗 HOT 2
- dinger class is empty HOT 1
- dinger-locations配置中使用*.xml提示找不到文件 HOT 9
- 支持配置多个钉钉消息接收token吗
- 能否配置多个群机器人,并指定群发送 HOT 2
- 企业微信wetalk不支持markdown格式的`@`功能? HOT 2
- 问下,可以给外部群聊推送消息吗? HOT 2
- 如何推送文件,如:excel,word等
- 能否支持按需自动配置
- 支持给钉钉个人发送消息
- 指定phone
- 兼容性问题
- 支持代理请求发送消息
- 无法在每次发送的时候指定token_id, token_id可能是动态的,无法用配置去覆盖全;
- 支持发送个人工作通知吗?
- 钉钉机器人webhook服务收回了,是否有计划更新到stream模式
- 这个项目现在不更新了吗? HOT 1
- 还有后续更新么?
- 目前只可以发送text 和mark down 类型的消息么 其他类型怎么发送 作者 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dingtalk-spring-boot-starter.