spring mvc servlet initialization

前端 未结 2 842
有刺的猬
有刺的猬 2020-12-14 13:04

I am new to spring MVC. I am looking for a place in my spring mvc applicationwhere I can initialize all sorts of things in the application. usually I did that in the init()

相关标签:
2条回答
  • 2020-12-14 13:37

    All beans can have an init-method. See the documentation. I suppose that the best practice will be to use this method for every bean you define. A bean can have references to other beans if this is required.

    0 讨论(0)
  • 2020-12-14 13:49

    Use a ServletContextListener and define it in web.xml:

    <listener>
        <listener-class>com.company.YourListenerClass</listener-class>
    </listener>
    

    (you make a class which implements ServletContextListener and implement the contextInitialized() method, where you place your initialization code)

    0 讨论(0)
提交回复
热议问题