課程
/后端開發
/Java
/Spring MVC起步
mvc-dispatcher-servlet.xml
2017-02-09
源自:Spring MVC起步 3-5
正在回答
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" ? ? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ? ? ? xmlns:context="http://www.springframework.org/schema/context" ? ? ? xmlns:mvc="http://www.springframework.org/schema/mvc" ? ? ? xsi:schemaLocation=" ? ? ? http://www.springframework.org/schema/beans ? ? ? http://www.springframework.org/schema/beans/spring-beans.xsd ? ? ? http://www.springframework.org/schema/context ? ? ? http://www.springframework.org/schema/context/spring-context.xsd ? ? ? http://www.springframework.org/schema/mvc ? ? ? http://www.springframework.org/schema/mvc/spring-mvc.xsd"> ? ?<!-- 本配置文件是工名為mvc-dispatcher的DispatcherServlet使用, 提供其相關的Spring MVC配置 --> ? ?<!--激活各種標簽注解--> ? ?<!-- 啟用Spring基于annotation的DI, 使用戶可以在Spring MVC中使用Spring的強大功能。 激活 @Required --> ? ?<!-- @Autowired,JSR 250's @PostConstruct, @PreDestroy and @Resource 等標注 --> ? ?<context:annotation-config/> ? ? ? ?<!--DispatcherServlet上下文--> ? ?<!-- DispatcherServlet上下文, 只管理@Controller類型的bean, 忽略其他型的bean, 如@Service --> ? ?<context:component-scan base-package="com.levin.mvcdemo.controller"> ? ? ? ?<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> ? ?</context:component-scan> ? ?<!-- HandlerMapping, 無需配置, Spring MVC可以默認啟動。 DefaultAnnotationHandlerMapping ?--> ? ?<!-- annotation-driven HandlerMapping --> ? ?<!--啟用基于annotation的handlerMapping--> ? ?<!-- 擴充了注解驅動,可以將請求參數綁定到控制器參數 --> ? ?<mvc:annotation-driven/> ? ?<!-- 靜態資源處理, css, js, imgs --> ? ?<mvc:resources mapping="/resources/**" location="/resources/" /> ? ?<!-- 配置ViewResolver。 可以用多個ViewResolver。 使用order屬性排序。 InternalResourceViewResolver放在最后。 --> ? ?<bean ? ? ? ? ? ?class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> ? ? ? ?<property name="order" value="1" /> ? ? ? ?<property name="mediaTypes"> ? ? ? ? ? ?<map> ? ? ? ? ? ? ? ?<entry key="json" value="application/json" /> ? ? ? ? ? ? ? ?<entry key="xml" value="application/xml" /> ? ? ? ? ? ? ? ?<entry key="htm" value="text/html" /> ? ? ? ? ? ?</map> ? ? ? ?</property> ? ? ? ?<property name="defaultViews"> ? ? ? ? ? ?<list> ? ? ? ? ? ? ? ?<!-- JSON View --> ? ? ? ? ? ? ? ?<bean ? ? ? ? ? ? ? ? ? ? ? ?class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"> ? ? ? ? ? ? ? ?</bean> ? ? ? ? ? ?</list> ? ? ? ?</property> ? ? ? ?<property name="ignoreAcceptHeader" value="true" /> ? ?</bean> ? ?<!--配置視圖解析器--> ? ?<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> ? ? ? ?<!--設置解析器類--> ? ? ? ?<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> ? ? ? ?<!--視圖解析前綴--> ? ? ? ?<property name="prefix" value="/WEB-INF/jsp/"/> ? ? ? ?<!--視圖解析后綴--> ? ? ? ?<property name="suffix" value=".jsp"/> ? ?</bean> ? ?<!--200*1024*1024即200M resolveLazily屬性啟用是為了推遲文件解析,以便捕獲文件大小異常 --> ? ?<bean id="multipartResolver" ? ? ? ? ?class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> ? ? ? ?<property name="maxUploadSize" value="209715200" /> ? ? ? ?<property name="defaultEncoding" value="UTF-8" /> ? ? ? ?<property name="resolveLazily" value="true" /> ? ?</bean></beans>
11慕名而來 提問者
這類配置文件只能口口相傳嗎?在spring官網上找不到??
舉報
Java中Spring MVC框架入門教程,快來看最易用的MVC框架
3 回答mvc-dispatcher-servlet.xml ??
3 回答mvc-dispatcher-servlet.xml
2 回答mvc-dispatcher-servlet.xml報錯,怎么回事呀?
1 回答mvc-dispatcher-servlet.xml文件為什么是空的,ALT+/沒用
4 回答mvn jetty:run 后一直報 Could not open ServletContext resource [/WEB-INF/configs/spring/mvc-dispatcher-servlet.xml]
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-02-09
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
? ? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? ? ? xmlns:context="http://www.springframework.org/schema/context"
? ? ? xmlns:mvc="http://www.springframework.org/schema/mvc"
? ? ? xsi:schemaLocation="
? ? ? http://www.springframework.org/schema/beans
? ? ? http://www.springframework.org/schema/beans/spring-beans.xsd
? ? ? http://www.springframework.org/schema/context
? ? ? http://www.springframework.org/schema/context/spring-context.xsd
? ? ? http://www.springframework.org/schema/mvc
? ? ? http://www.springframework.org/schema/mvc/spring-mvc.xsd">
? ?<!-- 本配置文件是工名為mvc-dispatcher的DispatcherServlet使用, 提供其相關的Spring MVC配置 -->
? ?<!--激活各種標簽注解-->
? ?<!-- 啟用Spring基于annotation的DI, 使用戶可以在Spring MVC中使用Spring的強大功能。 激活 @Required -->
? ?<!-- @Autowired,JSR 250's @PostConstruct, @PreDestroy and @Resource 等標注 -->
? ?<context:annotation-config/>
? ?
? ?<!--DispatcherServlet上下文-->
? ?<!-- DispatcherServlet上下文, 只管理@Controller類型的bean, 忽略其他型的bean, 如@Service -->
? ?<context:component-scan base-package="com.levin.mvcdemo.controller">
? ? ? ?<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
? ?</context:component-scan>
? ?<!-- HandlerMapping, 無需配置, Spring MVC可以默認啟動。 DefaultAnnotationHandlerMapping ?-->
? ?<!-- annotation-driven HandlerMapping -->
? ?<!--啟用基于annotation的handlerMapping-->
? ?<!-- 擴充了注解驅動,可以將請求參數綁定到控制器參數 -->
? ?<mvc:annotation-driven/>
? ?<!-- 靜態資源處理, css, js, imgs -->
? ?<mvc:resources mapping="/resources/**" location="/resources/" />
? ?<!-- 配置ViewResolver。 可以用多個ViewResolver。 使用order屬性排序。 InternalResourceViewResolver放在最后。 -->
? ?<bean
? ? ? ? ? ?class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
? ? ? ?<property name="order" value="1" />
? ? ? ?<property name="mediaTypes">
? ? ? ? ? ?<map>
? ? ? ? ? ? ? ?<entry key="json" value="application/json" />
? ? ? ? ? ? ? ?<entry key="xml" value="application/xml" />
? ? ? ? ? ? ? ?<entry key="htm" value="text/html" />
? ? ? ? ? ?</map>
? ? ? ?</property>
? ? ? ?<property name="defaultViews">
? ? ? ? ? ?<list>
? ? ? ? ? ? ? ?<!-- JSON View -->
? ? ? ? ? ? ? ?<bean
? ? ? ? ? ? ? ? ? ? ? ?class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
? ? ? ? ? ? ? ?</bean>
? ? ? ? ? ?</list>
? ? ? ?</property>
? ? ? ?<property name="ignoreAcceptHeader" value="true" />
? ?</bean>
? ?<!--配置視圖解析器-->
? ?<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
? ? ? ?<!--設置解析器類-->
? ? ? ?<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
? ? ? ?<!--視圖解析前綴-->
? ? ? ?<property name="prefix" value="/WEB-INF/jsp/"/>
? ? ? ?<!--視圖解析后綴-->
? ? ? ?<property name="suffix" value=".jsp"/>
? ?</bean>
? ?<!--200*1024*1024即200M resolveLazily屬性啟用是為了推遲文件解析,以便捕獲文件大小異常 -->
? ?<bean id="multipartResolver"
? ? ? ? ?class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
? ? ? ?<property name="maxUploadSize" value="209715200" />
? ? ? ?<property name="defaultEncoding" value="UTF-8" />
? ? ? ?<property name="resolveLazily" value="true" />
? ?</bean>
</beans>
2017-04-20
這類配置文件只能口口相傳嗎?在spring官網上找不到??