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.

  • GitHub comment 68#67777199
    via GitHub by pkraeutli
    ,
  • We are heavily using SpringLiquibase for keeping our executing our changesets. When we are starting our spring context on a server we get a FileNotFoundException per SpringLiquibase-Instance we are starting. Although the exception occured, the liquibase updates are executed without problems. Nevertheless the exception and the stacktrace in the log is quite annoying so we tried to get rid of it. Unfortunately the exception-logging uses {{liquibase.logging.LogFactory#getLog()}} which specifies one LoggerName (liquibase) for all liquibase-logs. So its not possible for us to set the logging level for liquibase.integration.spring.SpringLiquibase to ERROR without loosing all the other liquibase WARN logs. See the attached stacktrace below. You can reproduce the problem with the following [spring-boot repo|https://github.com/klausbayrhammer/spring-boot/tree/fileNotFoundException/spring-boot-samples/spring-boot-sample-liquibase]. You just have to execute * {{mvn clean package assembly:single}} * {{java -jar target/spring-boot-sample-liquibase-1.3.0.BUILD-SNAPSHOT-jar-with-dependencies.jar}} {noformat} WARNING 23/04/15 15:05: liquibase: Error initializing SpringLiquibase java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187) at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.init(SpringLiquibase.java:77) at liquibase.resource.AbstractResourceAccessor.<init>(AbstractResourceAccessor.java:22) at liquibase.resource.ClassLoaderResourceAccessor.<init>(ClassLoaderResourceAccessor.java:18) at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.<init>(SpringLiquibase.java:67) at liquibase.integration.spring.SpringLiquibase.createResourceOpener(SpringLiquibase.java:396) at liquibase.integration.spring.SpringLiquibase.createLiquibase(SpringLiquibase.java:357) at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:315) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:766) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:812) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687) at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) at org.springframework.boot.SpringApplication.run(SpringApplication.java:958) at org.springframework.boot.SpringApplication.run(SpringApplication.java:947) at sample.liquibase.SampleLiquibaseApplication.main(SampleLiquibaseApplication.java:33) {noformat}
    via by Klaus Bayrhammer,
  • I'll open a PR with a sample that reproduces the problem. It boils down to a call to {{ClassLoader.getResource("")}} returning {{null}} when there are only jars on the classpath. The failure is: {noformat} May 04, 2016 4:49:33 PM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@49c2faae: startup date [Wed May 04 16:49:33 BST 2016]; root of context hierarchy May 04, 2016 4:49:33 PM org.springframework.context.annotation.AnnotationConfigApplicationContext refresh WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManager' defined in com.example.ShadedClasspathRootApplication: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManager' defined in com.example.ShadedClasspathRootApplication: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) 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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84) at com.example.ShadedClasspathRootApplication.main(ShadedClasspathRootApplication.java:21) Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:591) at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:443) at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ... 11 more Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187) at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:588) ... 18 more {noformat} This also affects an executable jar built by Spring Boot. We used to have a hack in Boot's custom class loader that worked around this issue, but that doesn't help people who are using shaded jars, and we would prefer not to have to reintroduce the hack.
    via by Andy Wilkinson,
  • Spring + Spring Data JPA in Java SE standalone
    via Stack Overflow by crm86
    ,
    • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851)[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)[spring-context-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)[spring-boot-1.4.1.BUILD-SNAPSHOT.jar!/:1.4.1.BUILD-SNAPSHOT] at org.betterworldinternational.TheGoodCards2Application.main(TheGoodCards2Application.java:10)[classes!/:0.0.1-SNAPSHOT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[na:1.8.0_101] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[na:1.8.0_101] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[na:1.8.0_101] at java.lang.reflect.Method.invoke(Unknown Source)[na:1.8.0_101] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)[ward.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)[ward.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)[ward.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)[ward.jar:0.0.1-SNAPSHOT] Caused by: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:603)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:443)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet(DefaultPersistenceUnitManager.java:424)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:310)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)[spring-beans-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] ... 24 more Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:187)[spring-core-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:600)[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    19 more bugmates