web.xml是标准网络应用程序打包结构的一部分。这种结构允许你在Tomcat和Jetty等不同的服务器上部署打包的war文件。
你可以阅读更多关于web.xml中的位置:http://en.wikipedia.org/wiki/Deployment_descriptor
你可以阅读这里的标准目录结构(这是Tomcat的,但大部分网络服务器都遵循相同/相似的结构): http://tomcat.apache.org/tomcat-6.0-doc/appdev/deployment.html#Standard_Directory_Layout
如果你的应用程序是一个web应用程序,你应该已经有一个web.xml。如果没有,那么你应该而不是创建一个web.xml,但找到另一种挂钩在Spring安全的方式。请让我们知道您的应用程序目前如何部署。
这里是春天有个web.xml中使用Spring Security的例子:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Spring Security Filter -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- The front controller of the Spring MVC Web application, responsible
for handling all application requests -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/web-application-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
所有我想我必须包括一个web.xml后。 问题在于,使用Spring 3.1,您可以删除web.xml并仅使用基于注释的配置继续。但对于这样的情况 - 我无法找到合适的注释或指定Java类中的配置的方法。 也为'''我也必须包括web.xml,所以这是一个足够的理由。 –
2012-08-03 06:23:36
我会再添加一个提交,而不是指向XML Spring配置,web-application-config.xml,我可以说配置是注释驱动的,就像这个例子:https://gist.github。 com/1299632 – 2012-08-03 06:57:15
是的,这是正确的。如果你想使用@Configuration来配置你的bean,你可以在web.xml中使用AnnotationConfigWebApplicationContext。我认为这种方法是最新最好的方法。我将不得不更新我的项目以遵循它! – jasop 2012-08-03 07:54:30