0

Good day people. Right now in my web application I use a lot of Lists which will have to be sessionAttributes for my app. All this stored in one controller:

@Controller
@SessionAttributes({"institutionAttributes", "institutionTypeAttributes", "formDateAttributes", 
                        "formDescriptionAttributes", "deleteAttributesDescription", "deleteAttributesInstitution", "deleteAttributesDate"})
public class MainController {


    List<InstitutionInForm> listOfInstitutionsAttributes = new ArrayList<InstitutionInForm>();
    List<InstitutionTypeInForm> listOfInstitutionTypesAttributes = new ArrayList<InstitutionTypeInForm>();
    List<FormDate> listOfFormDateAttributes = new ArrayList<FormDate>();
    List<FormDescription> listOfFormDescriptionsAttributes = new ArrayList<FormDescription>();


    List<FormDescription> listOfFormDescriptionsDeleteAttributes = new ArrayList<FormDescription>();
    List<InstitutionInForm> listOfInstitutionDeleteAttributes = new ArrayList<InstitutionInForm>();
    List<FormDate> listOfDatesDeleteAttributes = new ArrayList<FormDate>();

//other methods omitted

Each of this Lists will initialize with initial value 10 and it takes some memory also. I decide to separate them by separating controllers.

So, I'm asking how it will initialize controllers all right on start up my application or when DispatcherServlet will get request from user, find a proper controller on after initialize them with all Lists inside.???

How can I prevent initializing don't needed at the moment controllers and Lists so on?

Thank you developers. Good productive coding day.

4

1 回答 1

3

您可以使用@Lazy来防止控制器 bean 的急切加载/初始化
一旦第一个请求到来,这将被实例化。

@Lazy
@Controller
public class MainController { ...}
于 2013-08-07T07:17:53.207 回答