spring mvc servlet初始化 [英] spring mvc servlet initialization
本文介绍了spring mvc servlet初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Spring MVC的新手。我在我的spring mvc应用程序中寻找一个地方,我可以在应用程序中初始化各种各样的东西。
通常我在我的主servlet的init()方法中做到了,但是现在调度程序servlet是spring的,我不能覆盖init函数。
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() method of the my main servlet but now the dispatcher servlet is of spring and I cannot overide the init function.
什么是最佳做法?
谢谢。
推荐答案
使用 ServletContextListener
并在 web.xml中定义
:
<listener>
<listener-class>com.company.YourListenerClass</listener-class>
</listener>
(你创建一个实现 ServletContextListener
的类并实现 contextInitialized()
方法,放置初始化代码)
(you make a class which implements ServletContextListener
and implement the contextInitialized()
method, where you place your initialization code)
这篇关于spring mvc servlet初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文