Spring Framework--DAY03SPRINGMVC and spring integration

Source: Internet
Author: User

One, SPRINGMVC and spring integration

SPRINGMVC is part of spring, so two frameworks don't need consolidation, but because Springmvc belongs to the Web tier, we want to separate the configuration of the Web layer. 1. Create the project and configure the necessary dependencies 2. Create three configuration Spring files in resources: Spring-web.xml spring-service.xml SPRING-DAO.XML3. Configuring Springmvc in Web. xml Front-end controllers, spring listeners, character set filters <filter> <filter-name>character</filter-name> <filter-class >org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <p Aram-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param&gt ; </filter> <filter-mapping> <filter-name>character</filter-name> &LT;URL-PATTERN&G t;/*</url-pattern> </filter-mapping> <servlet> <servlet-name>springmvc</servlet-na Me> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init -param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-web.xml</param-value> </init-param> & lt;/servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-patter n>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframewor k.web.context.contextloaderlistener</listener-class> </listener> <context-param> <param- Name>contextconfiglocation</param-name> <param-value>classpath:spring-service.xml,classpath: spring-dao.xml</param-value> </context-param>4. Configuring Spring-web.xml <context:component-scan Base-pack Age= "Com.lanou.controller"/> <!--annotated processor Mapper and processor adapter-<mvc:annotation-driven/> <be An class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name= "prefix" val Ue= "/jsp/"/> <pRoperty name= "suffix" value= ". jsp"/> </bean> </beans>5. Configuring Spring-service.xml and Spring-dao.xml SPR Ing-service.xml: <context:component-scan base-package= "Com.lanou.service"/> </beans> spri Ng-dao.xml: <context:component-scan base-package= "Com.lanou.dao"/> </beans>
Second, access to static resources in the SPRINGMVC
因为在web.xml中配置的前端控制器,拦截了所有资源请求,这其中也包括了静态资源,比如html,js,jpg... 所以在访问这些资源时,会404,具体流程如:

可以在springmvc的配置文件中加入以下配置:    <mvc:default-servlet-handler/>这样,静态资源就交给默认servlet来处理了。
 

Gmt
Detect languageAfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutch中文版EsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu AfrikaansAlbanianArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutch中文版EsperantoEstonianFilipinoFinnishFrenchGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanLaoLatinLatvianLithuanianMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPersianPolishPortuguesePunjabiRomanianRussianSerbianSesothoSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshYiddishYorubaZulu
Text-to-Speech function is limited to characters
Options:History:Feedback:Donate Close

Spring Framework--DAY03SPRINGMVC and spring integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.