As the NoSuchBeanDefinitionException
suggests, the error occurs because Spring fails to find the OrderFactoryFinland
bean. Since it has been annotated with @Component
, I guess that you intend to use component scanning to fetch it? Make sure that you have included the correct package. This applies regardless if you are using XML based configuration <context:component-scan ... >
or Java based config @ComponentScan(...)
.
On a higher level, all Spring beans are by default Singelton Scope, which means that there is only one shared instance of each bean in Spring's application context that gets dependency injected. Springs way of doing this is based on object instances which means that you should use instance methods (as opposed to static class methods) for your logic. The reason for this approach is that this allows Spring to add proxies for various reasons (caching, security, etc) in a simple, consistent manner.