Troubleshooting auto configuration in cloud foundry (#Springboot)
After CEOs, CIOs and power point loving SAs done with their talks of digital transformation, its time for real implementation! That is where larger tech community uses Spring framework (specifically Spring boot) for developing micro services based architecture (Just smaller portion of digital transformation!). I will keep this short - I want to highlight one of the issue which gives nightmare to teams when its not understood properly.
Spring boot has feature of auto configuration where it configures lot of beans out of the box, that is well known and very tempting feature - I love it. Now same application is deployed in CF and it does even more magic - it tries to auto configure beans which you have explicitly defined in your config code (Java config). Only if you have carefully analyzed the application start up log you will realize that feature. You would see statements like:
INFO 29 --- [ main] edisCloudServiceBeanFactoryPostProcessor : Auto-reconfiguring beans of type
INFO 29 --- [ main] edisCloudServiceBeanFactoryPostProcessor : Reconfigured bean redisConnectionFactory into singleton service connector org.springframework.data.redis.connection.jedis.JedisConnectionFactory@6839203borg.springframework.data.redis.connection.RedisConnectionFactory
Now you might have defined your own bean here with your custom configuration but it overwrites with its default (sometimes called opinionated). To give one more common example, if you have only one data source bean defined and you may have set connection pool to 10 or 15 - but when application will go to CF it will assign to only 4 connections - reason is they think in cloud resources might be limited for shared plan etc. (Below is KB entry that states same). Now if you expect more connections as you have coded but since you have not seen the logs - your application performance may be getting impacted and you may keep wondering why is this happening.
Solution for this type of problem is disabling auto configuration in spring boot for cloud foundry to take over control. If we just add config class by extending AbstractCloudConfig class it will turn it off (for all auto configuration).
Below are some useful links on this topic. Be aware of this and enjoy magic of CF, Springboot and beauty of auto configuration! Awareness of this issue among team members can save lot of hours spent in troubleshooting.
References:
https://discuss.pivotal.io/hc/en-us/articles/221898227-Connection-pool-warning-message-maxIdle-is-larger-than-maxActive-setting-maxIdle-to-4-seen-in-PCF-deployed-Spring-app
https://spring.io/blog/2015/04/27/binding-to-data-services-with-spring-boot-in-cloud-foundry