In a typical Spring MVC web app, you would declare the DispatcherServlet
in web.xml
like so
<!-- MVC Servlet -->
<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Along with listeners, filters, etc.
With servlet-api 3.0, you can declare your servlets with the annotation @WebServlet
instead of adding them to your web.xml
. Spring 3.2 already has @Configuration
and @EnableXYZ
for its context configuration. Does it have something similar for the DispatcherServlet
, ie. is there a way to configure your full Spring application without any xml?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…