0

コンストラクター注入を使用して Bean を作成し、Spring Cloud アノテーションでアノテーションを付けようとしています@EnableBinding

Spring Boot1.3.3と Spring Cloudを使用していBrixton.M5ます。

アプリの起動中に次の例外が発生します。

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

次の場合、この例外は消えます。

  1. @EnableBinding削除されます
  2. @Autowired引数なしのコンストラクターが導入されました (明らかに、引数を含むコンストラクターの注釈にもかかわらず、それが使用されます)
  3. 代わりにフィールド注入が使用されます

以下のコード スニペット:

@EnableBinding(Sink.class)
public class LocationReceiver {
//    @Autowired
    private final LocationModelRepository repository;

//    LocationReceiver() {
//        repository = null;
//    }

    @Autowired
    public LocationReceiver(LocationModelRepository repository) {
        this.repository = repository;
    }
}

CGLIB プロキシと何らかの関係があるのでしょうが、Spring 4 からコンストラクター インジェクションをサポートする必要があります。

誰が何が悪いのか考えていますか?それは私のせいですか、それとも Spring Cloud Data Flow のバグですか?

4

1 に答える 1

1

githubで Dave Syer から回答を得ました:

これ@EnableBindingは が であるためです@Configuration(そして、Spring 4.3 コンストラクター インジェクションが で機能しないまで@Configuration)。

于 2016-03-12T09:18:34.543 に答える