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

PersistenceExceptionTranslationInterceptor attempting to instantiate prototype PersistenceExceptionTranslator beans #26412

Closed
krm1312 opened this issue Jan 20, 2021 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: documentation A documentation task
Milestone

Comments

@krm1312
Copy link

krm1312 commented Jan 20, 2021

Affects: spring framework 5.3.3

Attempting to upgrade our application to boot 2.4.2 from 2.3.4 and ran into this issue.

We have a prototype bean defined as:

    @Bean(name = "protoConnectionFactory", autowireCandidate = false)
    @Scope(value = SCOPE_PROTOTYPE)
    public RedisConnectionFactory protoConnectionFactory(@NonNull Bar instance) {
    }

If there is a persistence exception this now causes the following exception (at runtime):

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'protoConnectionFactory' defined in FooConfig: Unsatisfied dependency expressed through method 'protoConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'foo.Bar' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
 at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
 at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory$1.orderedStream(DefaultListableBeanFactory.java:481)
 at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:167)
 at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:149)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:174)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
 at com.sun.proxy.$Proxy214.saveAndFlush(Unknown Source)

In other words, it is trying to instantiate the prototype bean now (RedisConnectionFactory is a PersistenceExceptionTranslator).

I believe this was caused by:

14839b1

Previously:

  Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
  beanFactory, PersistenceExceptionTranslator.class, false, false);

Excluded prototypes (the first false).

I'm pretty sure we could workaround this behavior by dynamically registering these beans (not using prototypes), but, this seems like a potential regression.

@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 20, 2021
@sbrannen
Copy link
Member

Possible regression caused by #24644.

@jhoeller jhoeller added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 20, 2021
@jhoeller jhoeller added this to the 5.3.4 milestone Jan 20, 2021
@jhoeller jhoeller modified the milestones: 5.3.4, 5.3.5 Feb 15, 2021
@jhoeller jhoeller modified the milestones: 5.3.5, 5.3.6 Mar 15, 2021
@jhoeller jhoeller modified the milestones: 5.3.6, 5.3.7 Apr 12, 2021
@jhoeller jhoeller modified the milestones: 5.3.7, 5.3.8 May 10, 2021
@jhoeller jhoeller modified the milestones: 5.3.8, 5.3.9 Jun 4, 2021
@jhoeller jhoeller modified the milestones: 5.3.9, 5.3.10 Jul 7, 2021
@krm1312
Copy link
Author

krm1312 commented Aug 11, 2021

Since nobody else seems to have hit this in 6 months, maybe we should consider this expected behavior now? Or, do you anticipate addressing it in a point release somewhat soon? Trying to determine whether to implement a workaround or not to avoid being stuck on an old release. Thanks.

@jhoeller jhoeller modified the milestones: 5.3.10, 5.x Backlog Sep 13, 2021
@jhoeller jhoeller added type: documentation A documentation task and removed type: regression A bug that is also a regression labels Nov 1, 2021
@jhoeller jhoeller modified the milestones: 5.x, 5.3.13 Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

3 participants