org.springframework.beans.factory.BeanCreationException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • A bean who refers to an empty java.util.Optional value cannot be created with Spring configuration xml. In Spring config xml file I have: {code:xml} <bean id="emptyOptional" class="java.util.Optional" factory-method="empty"/> {code} Then when the Spring config was loaded, it reported the following error: {noformat} [junit] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emptyOptional' defined in URL [file:configuration/spring-configuration/components/observers.xml]: Bean instantiation via factory method failed; nested exception is java.lang.IllegalArgumentException: Optional value must be present [junit] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [junit] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [junit] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [junit] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [junit] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [junit] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) [junit] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) [junit] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) [junit] at com.amazon.gpi.componentTesting.ComponentTestContext.createContext(ComponentTestContext.java:140) [junit] at com.amazon.gpi.componentTesting.ComponentTestContext.<init>(ComponentTestContext.java:117) [junit] at com.amazon.gpi.componentTesting.ComponentTestContext.fromProfile(ComponentTestContext.java:59) [junit] at com.amazon.gpi.componentTesting.TestProfileRunner.<init>(TestProfileRunner.java:130) [junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [junit] Caused by: java.lang.IllegalArgumentException: Optional value must be present [junit] at org.springframework.util.Assert.isTrue(Assert.java:68) [junit] at org.springframework.beans.AbstractNestablePropertyAccessor$OptionalUnwrapper.unwrap(AbstractNestablePropertyAccessor.java:1049) [junit] at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:207) [junit] at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:138) [junit] at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:194) [junit] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:595) {noformat} Looks like spring tried to extract the nested value of the Optional class and use that to assign to the bean which was not what I intended. (What I tried to do was to have both empty Optional and present Optional and later conditionally choose to use one of them. So if spring did not extract the nested value, it would just work (like if the Optional is from Guava.)) Thanks
    via by Yibo Wang,
  • A bean who refers to an empty java.util.Optional value cannot be created with Spring configuration xml. In Spring config xml file I have: {code:xml} <bean id="emptyOptional" class="java.util.Optional" factory-method="empty"/> {code} Then when the Spring config was loaded, it reported the following error: {noformat} [junit] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emptyOptional' defined in URL [file:configuration/spring-configuration/components/observers.xml]: Bean instantiation via factory method failed; nested exception is java.lang.IllegalArgumentException: Optional value must be present [junit] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) [junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [junit] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [junit] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [junit] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [junit] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [junit] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) [junit] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) [junit] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) [junit] at com.amazon.gpi.componentTesting.ComponentTestContext.createContext(ComponentTestContext.java:140) [junit] at com.amazon.gpi.componentTesting.ComponentTestContext.<init>(ComponentTestContext.java:117) [junit] at com.amazon.gpi.componentTesting.ComponentTestContext.fromProfile(ComponentTestContext.java:59) [junit] at com.amazon.gpi.componentTesting.TestProfileRunner.<init>(TestProfileRunner.java:130) [junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [junit] Caused by: java.lang.IllegalArgumentException: Optional value must be present [junit] at org.springframework.util.Assert.isTrue(Assert.java:68) [junit] at org.springframework.beans.AbstractNestablePropertyAccessor$OptionalUnwrapper.unwrap(AbstractNestablePropertyAccessor.java:1049) [junit] at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:207) [junit] at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:138) [junit] at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:194) [junit] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:595) {noformat} Looks like spring tried to extract the nested value of the Optional class and use that to assign to the bean which was not what I intended. (What I tried to do was to have both empty Optional and present Optional and later conditionally choose to use one of them. So if spring did not extract the nested value, it would just work (like if the Optional is from Guava.)) Thanks
    via by Yibo Wang,
    • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emptyOptional' defined in URL [file:configuration/spring-configuration/components/observers.xml]: Bean instantiation via factory method failed; nested exception is java.lang.IllegalArgumentException: Optional value must be present at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) at com.amazon.gpi.componentTesting.ComponentTestContext.createContext(ComponentTestContext.java:140) at com.amazon.gpi.componentTesting.ComponentTestContext.<init>(ComponentTestContext.java:117) at com.amazon.gpi.componentTesting.ComponentTestContext.fromProfile(ComponentTestContext.java:59) at com.amazon.gpi.componentTesting.TestProfileRunner.<init>(TestProfileRunner.java:130) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) Caused by: java.lang.IllegalArgumentException: Optional value must be present at org.springframework.util.Assert.isTrue(Assert.java:68) at org.springframework.beans.AbstractNestablePropertyAccessor$OptionalUnwrapper.unwrap(AbstractNestablePropertyAccessor.java:1049) at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:207) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:138) at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:194) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:595)

    Users with the same issue

    MattyMatty
    4 times, last one,
    pulse00pulse00
    5 times, last one,
    ivanszkypeterivanszkypeter
    1 times, last one,
    batwalrus76batwalrus76
    13 times, last one,
    Andreas HäberAndreas Häber
    1 times, last one,
    48 more bugmates