首页 > 编程语言 > 详细

Step-by-Step XML Free Spring MVC 3 Configuration--reference

时间:2014-04-09 22:52:44      阅读:818      评论:0      收藏:0      [点我收藏+]

The release of Spring 2.5 reduce the burden of XML by introduction annotation based configuration, but you still needed to bootstrap Spring in XML. However in Servlet 3 and Spring 3.1 we can now drop XML completely and have 100% code based configuration. All thanks to the Servlet 3 specification.

So lets see today how you can create Spring MVC application XML Free.

Step-by-Step Guide

Step 1) Create a Enterprise Java project in Eclipse and include Spring v3.1+ jars.

bubuko.com,布布扣

Step 2) Create a class which implements spring WebApplicationInitializer and override onStartup() method.
Inside onStartup() method, instantiate AnnotationConfigWebApplicationContext class and set ServletContext. We also need to set a base package name of your configuration files.

 

 

Step 3) Next step is to configure Spring MVC. I do that in following class.
@EnableWebMvc annotation used together with @Configuration enables default Spring MVC configuration, equivalent to . With @ComponentScan annotation we make sure our @Controller will be added to the application context. The configuration class also defines one @Bean: our default view resolver.

 

 

Step 4) Now create a simple Controller to see whether its working fine or Not.

 

 

Output

bubuko.com,布布扣

I really like this configuration changes in Spring MVC. It is easy to bootstrap the application with no xml files in place. Of course, this is not everything that Spring MVC 3 brings to the developers. With all the configuration in code it is so easy to refactor and navigate. No more back and forth with XML For more feature of spring mvc, please keep visiting TechZoo.

Happy Coding bubuko.com,布布扣

 

reference from:http://www.techzoo.org/spring-framework/step-by-step-xml-free-spring-mvc-3-configuration.html

Step-by-Step XML Free Spring MVC 3 Configuration--reference,布布扣,bubuko.com

Step-by-Step XML Free Spring MVC 3 Configuration--reference

原文:http://www.cnblogs.com/davidwang456/p/3653376.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!