Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Lifecycle of bean instantiation is not the same as regular runtime context #1014

Closed
snicoll opened this issue Sep 7, 2021 · 4 comments
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Contributor

snicoll commented Sep 7, 2021

Our instance supplier is taking care of creating the instance and applying autowiring. However, a traditional bean creation lifecycle is as follows, as far as I understood it:

  1. Instance creation
  2. Bean post-processing before initialization, typically invoking the Aware interface, see ApplicationContextAwareProcessor
  3. PropertyValues injection
  4. Bean post-processing after initialization, typically injecting @Autowired-annotated members

Right now, the order is more like 1, 4, 2, 3.

Invoking the aware interface is benign and doesn't involve reflection so we could keep it as is. Adding one post-processor per bean to apply autowiring sounds a bit invasive.

WDYT @jhoeller

@snicoll snicoll added the type: task A general task label Sep 7, 2021
@snicoll snicoll added this to the 0.11.0 milestone Sep 7, 2021
@snicoll snicoll added type: bug A general bug and removed type: task A general task labels Sep 7, 2021
@snicoll
Copy link
Contributor Author

snicoll commented Sep 22, 2021

I forgot about @PostConstruct& co so that makes it even more important to handle, see #1048

@snicoll snicoll self-assigned this Sep 22, 2021
@snicoll
Copy link
Contributor Author

snicoll commented Sep 24, 2021

A chat with @jhoeller helped me fix the ordering. It's rather 1, 4, 2, 3. Because PropertyValues come last and are handled outside of the instance supplier, we may got a chance to get away with the current arrangement.

@snicoll
Copy link
Contributor Author

snicoll commented Sep 28, 2021

We've started to register BeanPostProcessor when it makes sense and we shoud extent that to match framework's ordering. To summarize, it is:

  1. Instance creation
  2. Autowired injection
  3. Property Values
  4. Aware callbacks (incuding ImportAware)
  5. PostConstruct & co

It looks like moving the import aware callback in a BPP is all that we need at this point.

snicoll added a commit that referenced this issue Sep 28, 2021
This commit moves handling of ImportAware in a bean post processor to
match the ordering of the regular runtime. As a result, bean instance
descriptor does not have to know about instance callbacks.

Closes gh-1014
@snicoll
Copy link
Contributor Author

snicoll commented Sep 28, 2021

Closed by c603e0c

@snicoll snicoll closed this as completed Sep 28, 2021
snicoll added a commit that referenced this issue Sep 28, 2021
This commit moves handling of ImportAware in a bean post processor to
match the ordering of the regular runtime. As a result, bean instance
descriptor does not have to know about instance callbacks.

Closes gh-1014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

1 participant