Reputation: 745
I want to do the following in my Spring MVC application:
List<String> list
) in my @Service MainService
.list
as a constructor parameter for other @Service ConfigFactory
that I have currently @Autowired in MainService
.ConfigFactory
to 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?
Upvotes: 0
Views: 224
Reputation: 2254
Why don't you pass the list as a parameter to the getResult() method? I suppose that you get values from the list in the init() method, and you initialize some properties in your ConfigFactory? Don't do that, you will probably get problems when several users try to do the same thing.
Upvotes: 1