【问题标题】:org.springframework.beans.factory.wiring.BeanWiringInfo.BeanWiringInfo is initialized with null nameorg.springframework.beans.factory.wiring.BeanWiringInfo.BeanWiringInfo 用空名称初始化
【发布时间】:2017-01-11 02:57:56
【问题描述】:

我正在尝试使用 Spring Session 和 Aspectj 在会话序列化到 Redis 后重新连接 @Autowired 字段。

这是豆子:

@UIScope()
@SpringComponent(value = AboutView.VIEW_NAME)
@SpringView(name = AboutView.VIEW_NAME)    
//
@Configurable(autowire = Autowire.BY_NAME, value = AboutView.VIEW_NAME, dependencyCheck = false, preConstruction = true)
public class AboutView extends AbstractView {

    public static final String VIEW_NAME = "butterfly-effect-frontend-system:about";

    private Table tableFrontEndInformation;

    private GridLayout backendLayout;

    private GridLayout frontendLayout;

    @Autowired
    private transient DiscoveryClient discoveryClient;

此 bean 使用 @Configurable 和 bean 定义的名称(值)。不幸的是,方面正在创建一个带有空 bean 名称的 BeanWiringInfo,这将引发错误,因为名称是必需的。

@Configurable(autowire = Autowire.BY_NAME, value = AboutView.VIEW_NAME, dependencyCheck = false, preConstruction = true)

由于AnnotationBeanWiringInfoResolver调用的以下构造函数而发生错误

/**
     * Create a new BeanWiringInfo that points to the given bean name.
     * @param beanName the name of the bean definition to take the property values from
     * @param isDefaultBeanName whether the given bean name is a suggested
     * default bean name, not necessarily matching an actual bean definition
     * @throws IllegalArgumentException if the supplied beanName is {@code null},
     * is empty, or consists wholly of whitespace
     */
    public BeanWiringInfo(String beanName, boolean isDefaultBeanName) {
        Assert.hasText(beanName, "'beanName' must not be empty");
        this.beanName = beanName;
        this.isDefaultBeanName = isDefaultBeanName;
    }

AnnotationBeanWiringInfoResolver 从这段代码中实例化 BeanWiringInfo:

protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) {
        if (!Autowire.NO.equals(annotation.autowire())) {
            return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck());
        }
        else {
            if (!"".equals(annotation.value())) {
                // explicitly specified bean name
                return new BeanWiringInfo(annotation.value(), false);
            }
            else {
                // default bean name
                return new BeanWiringInfo(getDefaultBeanName(beanInstance), true);
            }
        }
    }

这是错误:

Caused by: java.lang.IllegalArgumentException: 'name' must not be null
    at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.BeanFactoryUtils.transformedBeanName(BeanFactoryUtils.java:72) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.transformedBeanName(AbstractBeanFactory.java:1109) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:970) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at com.vaadin.spring.internal.SpringViewDisplayPostProcessor.postProcessAfterInitialization(SpringViewDisplayPostProcessor.java:66) ~[classes/:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1594) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:400) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.wiring.BeanConfigurerSupport.configureBean(BeanConfigurerSupport.java:142) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect.configureBean(AnnotationBeanConfigurerAspect.aj:63) ~[spring-aspects-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.beans.factory.aspectj.AbstractDependencyInjectionAspect.ajc$before$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$1$e854fa65(AbstractDependencyInjectionAspect.aj:79) ~[spring-aspects-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at com.scipionyx.butterflyeffect.frontend.configuration.ui.view.AboutView.<init>(AboutView.java:72) ~[classes/:na]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_45]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[na:1.8.0_45]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    ... 107 common frames omitted

有人知道这个配置有什么问题吗?

非常感谢您对我们的帮助。

【问题讨论】:

    标签: spring spring-boot vaadin aspectj spring-session


    【解决方案1】:

    我仍在尝试了解原因,但似乎从 @Configuration 中删除 autowire = Autowire.BY_NAME 似乎可以解决问题。

    现在这个类看起来像这样:

    @UIScope()
    @SpringComponent(value = AboutView.VIEW_NAME)
    @SpringView(name = AboutView.VIEW_NAME)
    
    //
    @Configurable(value = AboutView.VIEW_NAME)
    public class AboutView extends AbstractView {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-05
      • 2017-08-06
      • 1970-01-01
      • 2021-06-30
      • 2019-01-21
      • 2018-07-15
      • 2018-05-11
      • 2018-03-08
      相关资源
      最近更新 更多