Using Spring in standalone apps

前端 未结 4 1429
长发绾君心
长发绾君心 2020-12-18 11:31

I am learning Spring and I have a question regarding how you use it in standalone applications (and also when using it for making web applications). The examples I have been

4条回答
  •  旧时难觅i
    2020-12-18 12:21

    It kind of depends on the application you are writing, but you should limit getBean() invocations to minimum, preferably one. You are fetching the first bean directly from the context and put the rest of the logic in the beans themselves. Something along the lines:

    Bootstrap boot = context.getBean(Bootstrap.class);
    boot.start();
    

    And all the rest of your application logic is taking place within start(). It can create threads, listen for events, etc.

提交回复
热议问题