Cumulocity 实施新协议

Cumulocity implementing new protocol

我正在研究跟踪器代理并尝试添加一个新协议以用于我的设备。我试图模仿您对 GL200 协议所做的操作,但是当它达到 TrackerFactory.create() 时,它 returns 出现以下错误:

16:05:47.912 [pool-2-thread-1] ERROR c8y.trackeragent.RequestHandler - Error handling request:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectedAXTracker': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected java.util.List c8y.trackeragent.ConnectedTracker.fragments; nested exception is org.springframework.beans.factory.NoSuchBeanDefinition
Exception: No qualifying bean of type [c8y.trackeragent.Fragment] found for dependency [collection of c8y.trackeragent.Fragment]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:217) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:350) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at c8y.trackeragent.protocol.mapping.TrackerFactory.create(TrackerFactory.java:76) ~[classes/:na]
        at c8y.trackeragent.protocol.mapping.TrackerFactory.discoverTracker(TrackerFactory.java:48) ~[classes/:na]
        at c8y.trackeragent.protocol.mapping.TrackerFactory.getTracker(TrackerFactory.java:33) ~[classes/:na]
        at c8y.trackeragent.RequestHandler.run(RequestHandler.java:32) ~[classes/:na]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected java.util.List c8y.trackeragent.ConnectedTracker.fragments; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [c8y.trackeragent.Fragment] found for dependency [collection of c8y.trackeragent.Fragment]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        ... 14 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [c8y.trackeragent.Fragment] found for dependency [collection of c8y.trackeragent.Fragment]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]

        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1006) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE]
        ... 16 common frames omitted

我不知道Spring,你能给我提示吗?

从堆栈跟踪来看,这件事发生了: 它发现跟踪器连接是您添加的类型,但是在尝试实例化 class 时失败,因为它无法设置 class.

所需的碎片列表

每个跟踪器协议至少需要一个片段(class 实现 c8y.trackeragent.Fragment)。

如果您查看 GL200 实现,还有另一个接口 GL200Fragment,然后例如解析器 (GL200Parser) 实现该接口。看起来您没有添加任何实现此接口的 class。

我发现了问题:我的 类 扩展了 AXFragment 接口(本身扩展了 Fragment)没有被标记为 @Component。