Skip to content

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

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

Closed
spring-projects-issues opened this issue Jan 18, 2008 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 18, 2008

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I've fixed this for Spring 2.5.2, introducing a dedicated "ScriptFactory.requiresScriptedObjectRefresh(ScriptSource)" method that takes into account whether a modified source has been found for a type check, indicating the need for a refresh until the next getScriptedObject call from the TargetSource.

This will be available in the next nightly 2.5.2 snapshot (-377 or higher, from http://static.springframework.org/downloads/nightly/snapshot-download.php?project=SPR). Please give it a try and let me know whether it works for you...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Roman Urosov commented

Now it's working well.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants