spring-cloud / spring-cloud/spring-cloud-commons

Support validation of properties on refresh

Open
#648 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
751
Forks
744
Avg merge
1d 14h
Merged PRs (30d)
9

Description

I am using spring cloud configuration.

I have a property bean annotated with @RefreshScope, it keeps my dynamic properties, it refreshes my applicationContext using ContextRefresher after noticing my properties changed, I found that when new properties invalid, it can also refreshes successfully, but when I used this property bean, it throwed a exception with message "error creating a bean with name 'xxx'".

I looked up source code and found the reason, when ContextRefresher refreshed, beans in refresh scope will be destroyed, new bean will not be created immediately because of lazyInit. It created when I first used it, and then spring resolved new properties failed, leads to new bean create fail, so I got the exception. And worse, every time I use it, it is created again and the exception occurs again.

I hope that it could fallback to old properties bean when new properties is invalid.

Sorry for my poor English, Looking forward to your reply.

Thanks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading ContextRefresher and the @RefreshScope lifecycle described in the report, focusing on destruction, lazy creation, and validation of refreshed properties. Reproduce the invalid-property case and trace repeated bean creation failures. Done means an invalid refresh does not discard the previously valid property bean, with tests covering the refresh and subsequent access.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.