首页 > 代码库 > springmvc配置文件 spring-servlet

springmvc配置文件 spring-servlet

<?xml version="1.0" encoding="UTF-8"?>
<!-- Bean头部 -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

<!-- 激活@Controller模式 -->
<mvc:annotation-driven />

<!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 需要更改 -->
<context:component-scan base-package="com.imooc.ssh">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Service" />
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Repository" />
</context:component-scan>

<mvc:resources location="/images/" mapping="/images/**" />
<mvc:resources location="/js/" mapping="/js/**" />
<mvc:resources location="/style/" mapping="/style/**" />
<mvc:resources location="/img/" mapping="/img/**" />

<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="cacheSeconds" value="http://www.mamicode.com/0"></property>
<property name="messageConverters">
<list>
<ref bean="mapping" />
</list>
</property>
<property name="webBindingInitializer" ref="webBindingInitializer">
</property>
</bean>

<bean id="mappingStringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>

<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="http://www.mamicode.com/application"></constructor-arg>
<constructor-arg index="1" value="http://www.mamicode.com/json"></constructor-arg>
<constructor-arg index="2" value="http://www.mamicode.com/UTF-8"></constructor-arg>
</bean>
</list>
</property>
</bean>

<bean id="webBindingInitializer"
class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService">
<bean
class="org.springframework.core.convert.support.DefaultConversionService"></bean>
</property>
</bean>

<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
id="viewResolver">
<property name="ignoreAcceptHeader" value="http://www.mamicode.com/true" />
<property name="mediaTypes">
<map>
<entry key="json" value="http://www.mamicode.com/application/json"></entry>
<entry key="xml" value="http://www.mamicode.com/application/xml"></entry>
</map>
</property>
<property name="defaultContentType" value="http://www.mamicode.com/text/html"></property>
<property name="favorParameter" value="http://www.mamicode.com/false"></property>
<property name="viewResolvers">
<list>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="http://www.mamicode.com/2"></property>
<property name="prefix" value="http://www.mamicode.com/WEB-INF/views/"></property>
<property name="suffix" value="http://www.mamicode.com/.jsp"></property>
</bean>

</list>
</property>

</bean>
</beans>

springmvc配置文件 spring-servlet