博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Step-by-Step XML Free Spring MVC 3 Configuration--reference
阅读量:7133 次
发布时间:2019-06-28

本文共 4225 字,大约阅读时间需要 14 分钟。

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.

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

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 :)

 

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

转载地址:http://ukcrl.baihongyu.com/

你可能感兴趣的文章
部署rails项目到heroku
查看>>
SWAP_JOIN_INPUTS Oracle Hint(处理hash join强制大表(segment_size大)作为被驱动表)
查看>>
oc引入头文件
查看>>
ORACLE联机日志文件丢失或损坏的处理方法(转)
查看>>
bootstrap-导航加下拉菜单(二级导航)
查看>>
ZOJ 2702 Unrhymable Rhymes 贪心
查看>>
apt-get update更新源时,出现“Hash Sum mismatch”问题
查看>>
ExtJS 2.x + Google Maps JavaScript API V3
查看>>
[译]何时使用 Parallel.ForEach,何时使用 PLINQ
查看>>
第 43 章 SonicWALL
查看>>
解决VS2015 VBCSCompiler.exe 占用CPU100%的问题
查看>>
[转载]我的程序 能节能休眠
查看>>
将IRepository接口进行抽象,使它成为数据基类的一个对象,这样每个子类都可以有自己的最基础的CURD了...
查看>>
WF中的动态更新
查看>>
T-SQL查询进阶--深入理解子查询
查看>>
带权并查集(个人模版)
查看>>
【JUnit 报错】java.lang.IncompatibleClassChangeError
查看>>
3D打印——只有你想不到的,没有 它做不到的
查看>>
如何从github上面拷贝源码
查看>>
适用于WinForm的一个定时器类
查看>>