0

I want to do the following in my Spring MVC application:

  1. Get some data from the database (It will return List<String> list ) in my @Service MainService.
  2. Use this list as a constructor parameter for other @Service ConfigFactory that I have currently @Autowired in MainService.
  3. Fire a method from 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?

4

1 回答 1

1

为什么不将列表作为参数传递给 getResult() 方法?我想您从 init() 方法中的列表中获取值,并在您的 ConfigFactory 中初始化一些属性?不要那样做,当几个用户尝试做同样的事情时,你可能会遇到问题。

于 2013-07-10T11:59:33.893 回答