Using Spring in standalone apps

前端 未结 4 1414
长发绾君心
长发绾君心 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条回答
  •  感情败类
    2020-12-18 12:34

    If you're calling context.getBean() everywhere, you're probably missing the whole point of Spring, which is a dependency injection framework.

    In a standalone app, you typically call context.getBean() only once (or at least, very rarely), in order to get a "root" bean. This bean is injected by Spring with other beans, and so on.

    In a web app, it all depends on which framework you use. But typically, you register a listener in the web.xml which loads the context for you, and controllers are created and/or injected by Spring.

提交回复
热议问题