Skip to content
Advertisement

Factory design patter Spring Boot double bean

JavaScript
JavaScript
JavaScript
JavaScript

Calling method executeSPV from abstract class

JavaScript

If I remove @Componet from Upload and Download classes I receive error I need to add Bean for abstrcat class CommndBase

If I use @Compoment on Upload and Download classes I receive dual Bean is useed… Field command in .Controller required a single bean, but 2 were found:

Advertisement

Answer

You should not use @Component for abstract class, because Spring context will not be able to initialize that bean. You should remove it then.

Another thing is the way you want to implement a factory pattern here – I recommend you the way described here: https://stackoverflow.com/a/39361500/14056755, refactored version https://stackoverflow.com/a/55060326/14056755.

Advertisement