I want to do the following in my Spring MVC application:
- Get some data from the database (It will return
List<String> list) in my @ServiceMainService. - Use this
listas a constructor parameter for other @ServiceConfigFactorythat I have currently @Autowired inMainService. - Fire a method from
ConfigFactoryto get final result that will be added to ModelAndView in my @Controller class.
I know it would be possible to this that way:
ConfigFactory class:
@Service
public class ConfigFactory(){
public void init(List<String> list){
//Use list to initialize ConfigFactory
}
public Result getResult(){
//Do some business logic
return result;
}
}
MainService class:
@Service
public class MainService {
@Autowired ConfigFactory configFactory;
public Result method(){
//Get list from database;
configFactory.init(list);
Result result = configFactory.getResult();
//Create a Result that will be later added to controller ModelAndView.
}
}
But it doesn't feel nice. So I'm stuck here. Does anyone have an idea how to properly realize this?