0
我正嘗試使用構造函數注入創建一個bean,並使用Spring Cloud @EnableBinding
註釋對其進行註釋。Spring雲數據流@EnableBinding註釋中斷構造函數注入
我使用的是Spring Boot 1.3.3
和Spring Cloud Brixton.M5
。
我的應用程序在啓動過程中收到以下情況例外:如果
@EnableBinding
被刪除- 無參數的構造函數介紹(很明顯,它的使用,那麼儘管
@Autowired
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'locationReceiver' defined in file [<path>/projects/location/location-microservice/target/classes/<xxx>/location/microservice/stream/LocationReceiver.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [xxx.location.microservice.stream.LocationReceiver$$EnhancerBySpringCGLIB$$b2012a14]: No default constructor found; nested exception is java.lang.NoSuchMethodException: xxx.location.microservice.stream.LocationReceiver$$EnhancerBySpringCGLIB$$b2012a14.<init>() at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE] at xxx.location.microservice.LocationMicroservice.main(LocationMicroservice.java:13) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_72] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_72] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_72] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_72] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.3.3.RELEASE.jar:1.3.3.RELEASE] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [xxx.location.microservice.stream.LocationReceiver$$EnhancerBySpringCGLIB$$b2012a14]: No default constructor found; nested exception is java.lang.NoSuchMethodException: xxx.location.microservice.stream.LocationReceiver$$EnhancerBySpringCGLIB$$b2012a14.<init>() at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] ... 22 common frames omitted Caused by: java.lang.NoSuchMethodException: xxx.location.microservice.stream.LocationReceiver$$EnhancerBySpringCGLIB$$b2012a14.<init>() at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_72] at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_72] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] ... 23 common frames omitted
此異常消失包含參數的構造函數註釋)
- 使用場注入
代碼下面的代碼片段:
@EnableBinding(Sink.class)
public class LocationReceiver {
// @Autowired
private final LocationModelRepository repository;
// LocationReceiver() {
// repository = null;
// }
@Autowired
public LocationReceiver(LocationModelRepository repository) {
this.repository = repository;
}
}
我想這是某種聯繫CGLIB代理,但它應該支持構造函數注入從春4
開始是否有人有一個想法有什麼不對?這是我的錯,還是Spring Cloud Data Flow中的一個錯誤?