Spring MVC Configuration

Source: Internet
Author: User

1,

RootConfig used to configure Contextloadlistener

1 @Configuration2 //@Import (Dataconfig.class)3@ComponentScan (basepackages={"Spittr"}, 4excludefilters={5@Filter (Type=filtertype.custom, Value=webpackage.class)6     })7  Public classRootConfig {8    Public Static classWebPackageextendsRegexpatterntypefilter {9      PublicWebPackage () {Ten       Super(Pattern.compile ("Spittr\\.web")); One     }     A   } -}
RootConfig

Webconfig used to configure Dispatcherservlet

1 @Configuration2 @EnableWebMvc3@ComponentScan ("Spittr.web")4  Public classWebconfigextendsWebmvcconfigureradapter {5 6 @Bean7    Publicviewresolver Viewresolver () {8Internalresourceviewresolver resolver =Newinternalresourceviewresolver ();9Resolver.setprefix ("/web-inf/views/");TenResolver.setsuffix (". JSP"); One     returnResolver; A   } -    - @Override the    Public voidconfiguredefaultservlethandling (Defaultservlethandlerconfigurer configurer) { - configurer.enable (); -   } -    + @Override -    Public voidaddresourcehandlers (Resourcehandlerregistry registry) { +     //TODO auto-generated Method Stub A     Super. Addresourcehandlers (registry); at   } -  -}
Webconfig

Create the above 2 context

 Public classSpitterwebinitializerextendsAbstractannotationconfigdispatcherservletinitializer {@OverrideprotectedClass<?>[] getrootconfigclasses () {return NewClass<?>[] {rootconfig.class }; } @OverrideprotectedClass<?>[] getservletconfigclasses () {return NewClass<?>[] {webconfig.class }; } @Overrideprotectedstring[] Getservletmappings () {return NewString[] {"/" }; }}
Spitterwebinitializer

If you find that the object display in the JSP does not work properly, it is possible that Web. XML is not configured to a newer schema, it should be:

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Web-appxmlns= "Http://xmlns.jcp.org/xml/ns/javaee"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"5 version= "3.1">6 7 8 9 </Web-app>

Spring MVC Configuration

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.