Skip to content

Refreshable beans are not updated if AbstractApplicationContext.getBeansOfType() is called [SPR-4356] #9034

Closed
@spring-projects-issues

Description

@spring-projects-issues

Roman Urosov opened SPR-4356 and commented

When AbstractApplicationContext.getBeansOfType() is called, all instances of ResourceScriptSource updates their lastModified property (if script file is updated), but bean itself remains unrefreshed.
Therefore, when user calls refreshable bean, the corresponding check (requiresRefresh()) returns false and user gets an old instance of bean.

Here are some stack traces:

First, calling AbstractApplicationContext.getBeansOfType() for arbitrary bean type.

main@1, priority=5, in group 'main', status: 'RUNNING'
getScriptAsString():91, ResourceScriptSource.java <-- lastModified is updated, but bean is not reloaded
getScriptedObjectType():191, GroovyScriptFactory.java
predictBeanType():240, ScriptFactoryPostProcessor.java
predictBeanType():488, AbstractAutowireCapableBeanFactory.java
getBeanNamesForType():212, DefaultListableBeanFactory.java
getBeansOfType():294, DefaultListableBeanFactory.java
getBeansOfType():288, DefaultListableBeanFactory.java
getBeansOfType():949, AbstractApplicationContext.java <-- searching for beans of any type

Then, trying to call refreshable bean, but it does not refresh:

main@1, priority=5, in group 'main', status: 'RUNNING'
isModified():113, ResourceScriptSource.java <-- returns false
requiresRefresh():60, RefreshableScriptTargetSource.java
getTarget():81, AbstractRefreshableTargetSource.java
invoke():184, JdkDynamicAopProxy.java
getMetaClass():-1 <--- calling refreshable bean method


Affects: 2.5.1

Issue Links:

1 votes, 1 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions