spring mvc配置

<mvc:annotation-driven/>
    <context:component-scan base-package="com.action"></context:component-scan>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/page/"/>  
        <property name="suffix" value=".html"/>  
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />  
    </bean> 

spring-mvc  视图解析器配置如上。



配置web.xml

<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<servlet>
		<servlet-name>Control</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/spring-servlet.xml</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>Control</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

	<!-- Spring监听器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- 防止Spring内存溢出监听器 -->
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>
	<!-- spring bean的配置的位置,如果没有这句话,就是默认在web-inf目录下查找applicationContext.xml -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:spring/spring-all.xml</param-value>
	</context-param>

一个spring bean配置文件和spring-servlet配置文件要注意位置



spring除了servelt为难能走同一个配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
    <import resource="classpath:spring/spring-jdbc.xml"/>   
   			   
</beans>


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页