spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
590 stars 376 forks source link

SimpleStorageProtocolResolver leads to early bean construction if application defines AmazonS3 bean #678

Closed QwertGold closed 3 years ago

QwertGold commented 3 years ago

Describe the bug We recently upgraded to Hoxton.SR1 to SR8, and our code stopped working, After some debugging it turns out that SimpleStorageProtocolResolver gets registered as an ordered BeanFactoryPostProcessor, and it is now instantiated during a much earlier phase of the Application context refresh(). If the user's application defines the AmazonS3 bean this is very bad, because all PostProcessors are not loaded at this point, which means @Value, @PostConstruct and @Autowired annotation are not processed for any @Bean/@Configurations that is AmazonS3 depends on.

Sample I have build a small self contained project that demonstrates this issue https://github.com/QwertGold/springcloudbug Although this uses AWS, you don't need to configure anything, as the problem is clearly during bean initialization. Just put a breakpoint inside the @Bean method which creates the AmazonS3 instance, you will notice that @PostConstruct is not called with SR8, but it is called with SR1. I don't know a good way of writing a test for this, since the problem occurs during bean initialization. You will probably have to investigate why Spring considers SimpleStorageProtocolResolver an ordered BeanFactoryPostProcessor and decides to instantiate it in PostProcessorRegistrationDelegate line 172 (Spring 5.2.8)

eddumelendez commented 3 years ago

@QwertGold thanks for the report. We had similar reports and it is already fixed via https://github.com/spring-cloud/spring-cloud-aws/pull/658. You can test the snapshots and let us know if it is working for you. I will close the issue but reopen it if it is now working please.