最近在使用Spring+Hibernate框架开发项目,这里贴几个配置文件,以便用时查阅。
web.xml配置文件 1 <?xml version="1.0" encoding="UTF-8"?>
2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
3 <display-name>admin</display-name>
4 <welcome-file-list>
5 <welcome-file>index.html</welcome-file>
6 <welcome-file>index.htm</welcome-file>
7 <welcome-file>index.jsp</welcome-file>
8 <welcome-file>default.html</welcome-file>
9 <welcome-file>default.htm</welcome-file>
10 <welcome-file>default.jsp</welcome-file>
11 </welcome-file-list>
12
13 <context-param>
14 <param-name>contextConfigLocation</param-name>
15 <param-value>
16 /WEB-INF/spring/applicationContext*.xml
17 </param-value>
18 </context-param>
19 <listener>
20 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
21 </listener>
22 <listener>
23 <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
24 </listener>
25 <servlet>
26 <servlet-name>admin</servlet-name>
27 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
28 <init-param>
29 <param-name>contextConfigLocation</param-name>
30 <param-value>/WEB-INF/spring/spring-mvc.xml</param-value>
31 </init-param>
32 <load-on-startup>1</load-on-startup>
33 </servlet>
34 <servlet-mapping>
35 <servlet-name>admin</servlet-name>
36 <url-pattern>/</url-pattern>
37 </servlet-mapping>
38 </web-app>
spring-mvc.xml配置文件 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
7
8
9 <context:component-scan base-package="com.vvvedu"
10 use-default-filters="false">
11 <context:include-filter expression="org.springframework.stereotype.Controller"
12 type="annotation" />
13 </context:component-scan>
14 <bean
15 class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
16 <bean
17 class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
18
19 <!-- Allows for mapping the DispatcherServlet to "/" by forwarding static
20 resource requests to the container's default Servlet -->
21 <mvc:default-servlet-handler />
22
23 <mvc:view-controller path="/" view-name="adminmanage" />
24
25 <!-- View Resolver -->
26 <bean id="viewResolver"
27 class="org.springframework.web.servlet.view.UrlBasedViewResolver">
28 <property name="viewClass"
29 value="org.springframework.web.servlet.view.JstlView" />
30 <property name="prefix" value="/WEB-INF/views/"/>
31 <property name="suffix" value=".jspx" />
32 </bean>
33
34 </beans>
35