Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating bean with name 'jpaContext' [DATAJPA-1045] #1389

Closed
spring-projects-issues opened this issue Jan 16, 2017 · 2 comments
Closed
Assignees
Labels
in: core Issues in core support status: duplicate A duplicate of another issue type: bug A general bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Jan 16, 2017

Alexey Ariskin opened DATAJPA-1045 and commented

After upgrading Spring from 4.2.3 to 4.3.5 and Spring Data JPA from 1.9.4 to 1.10.6 (the latest available at the moment), the following exception occurs during the application startup:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jpaContext': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.Set<javax.persistence.EntityManager>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1154)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1056)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	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:759)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1101)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1816)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.Set<javax.persistence.EntityManager>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1474)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1102)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
	... 28 more

If we downgrade Spring Data JPA back to 1.9.4 (but still use Spring 4.3.5), all works pretty well.

We found this issue: https://jira.spring.io/browse/DATAJPA-956 and the following commit that fixes DATAJPA-956: 585ada9 . But it looks like fixing DATAJPA-956 broke application for us.

We don't use JNDI for data source, and we have the following EntityManagerFactory bean defined in applicationContext.xml:

<bean id="entityManagerFactory"
     class="com.tecomgroup.energetics.server.DefaultEntityManagerFactory" 
     init-method="afterPropertiesSet" destroy-method="destroy">
     ...
</bean>

DefaultEntityManagerFactory is a class that implements EntityManagerFactory interface:

package com.tecomgroup.energetics.server;

public class DefaultEntityManagerFactory implements EntityManagerFactory {
...
}

Because of the following lines from the commit mentioned above:

} else if (!EntityManagerFactory.class.equals(beanFactory.getType(name))) {
     return;
 }

our EntityManagerFactory bean is not added to the bean definitions.

Shouldn't this line use method like Class.isInstance() rather than just compare two Class objects?


Affects: 1.10.6 (Hopper SR6)

Issue Links:

  • DATAJPA-1005 Error bootstrapping Spring Data JPA with EntityManagerFactory already semi-initialized
    ("duplicates")

Referenced from: commits 9c6a6a7, 0d6376d, ba94c48

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 17, 2017

Alexey Ariskin commented

Looks like this issue duplicates DATAJPA-1005

@spring-projects-issues
Copy link
Author

spring-projects-issues commented May 22, 2019

Jens Schauder commented

Batch closing resolved issue without a fix version and a resolution indicating that there is nothing to release (Won't fix, Invalid ...)

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core support status: duplicate A duplicate of another issue labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants