Reputation: 161
Want put a class in a HashMap. For that I have created a Bean with @Service. This is it:
@Service
public class ServiceManagerImpl implements ServiceManager {
@Override
public void registerService() {
// registerService will put this in the HashMap!
dispatcher.registerService("serviceList", getServiceListImpl());
}
@Bean
public BusinessService getServiceListImpl() {
return new ServiceListManager();
}
}
Is this the right way to make something like this?
Upvotes: 1
Views: 2007
Reputation: 16485
Move your bean definition from a class annotated with @Service to a configuration class annotated with @Configuration (or at least move to your main class which has @SpringBootApplication annotation, if you have). Then Autowire that bean here in the Service class. `
@Autowired BusinessService businessService
take a look here Where to put @Bean in Spring Boot?
Upvotes: 1