Spring MVC零配置(全注解)(版本5.0.7)
// 核心配置类
package spittr.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class SpittrWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return new Class<?>[] {RootConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
// 指定配置类
return new Class<?>[] {WebConfig.class};
}
/**
* 将一个或多个路径映射到DispatcherServlet上
*/
@Override
protected String[] getServletMappings() {
// 将DispatcherServlet映射到“/”
return new String[] {"/"};
}
}
package spittr.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc // 启用Spring MVC
@ComponentScan("spittr.web") // 启用组件扫描
public class WebConfig implements WebMvcConfigurer {
/**
* 配置JSP视图解析器
*
* @return
*/
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
package spittr.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@ComponentScan(basePackages= {"spitter"},
excludeFilters= {
@Filter(type=FilterType.ANNOTATION, value=EnableWebMvc.class)
})
public class RootConfig {
}
package spittr.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
static {
System.out.println("=============HomeController============");
}
@RequestMapping("/home")
public String home() {
System.out.println("hellow");
return "home";
}
}
Spring MVC零配置(全注解)(版本5.0.7)的更多相关文章
- Spring MVC 零配置 / Spring MVC JavaConfig
1. Spring MVC的核心就是DispatcherServlet类,Spring MVC处理请求的流程如下图所示: 2. Spring MVC中典型的上下文层次 当我们初始化一个Dispatch ...
- 【1】springmvc4 + servlet3 零配置全注解入门项目helloword
自从servlet3.0支持注解,使得javaweb项目使用全注解成为可能. 注解化将成为javaweb的发展方向.包括spring去年推出的spring-boot也是全部使用注解. 代码:https ...
- struts 多文件上传 annotation注解(零配置)+ ajaxfileupload + 异步 版本
[本文简介] struts 多文件上传.基于”零配置“+"ajaxfileupload" 的一个简单例子. [导入依赖jar包] jquery-1.7.2.js : http:// ...
- 改造继续之eclipse集成tomcat开发spring mvc项目配置一览
在上一篇的环境配置中,你还只能基于maven开发一个javase的项目,本篇来看如果开发一个web项目,所以还得配置一下tomcat和spring mvc. 一:Tomcat安装 在.net web开 ...
- Spring MVC的配置和使用
Spring MVC的配置和使用 笔记仓库:https://github.com/nnngu/LearningNotes Spring MVC需要的jar包 文章中 Spring MVC 使用的版本是 ...
- J2EE进阶(十三)Spring MVC常用的那些注解
Spring MVC常用的那些注解 前言 Spring从2.5版本开始在编程中引入注解,用户可以使用@RequestMapping, @RequestParam,@ModelAttribute等等这样 ...
- Spring boot 零配置开发微服务
2018年12月29日星期六 体验Spring boot 零配置开发微服务 1.为什么要用Spring boot? 1.1 简单方便.配置少.整合了大多数框架 1.2 适用于微服务搭建,搭建的微服务 ...
- Spring MVC 事务配置
Spring MVC事务配置 要了解事务配置的所有方法,请看一下<Spring事务配置的5种方法> 本文介绍两种配置方法: 一. XML,使用tx标签配置拦截器实现事务 一. ...
- spring mvc+myBatis配置详解
一.spring mvc Spring框架(框架即:编程注解+xml配置的方式)MVC是Spring框架的一大特征,Spring框架有三大特征(IOC(依赖注入),AOP(面向切面),MVC(建模M- ...
随机推荐
- RuPengWang项目
项目 Day1------------------------- 说明:建外键约束.ashx+Razor RupengWang创建三个类库Model DAL BLL后台:RupengWang.Admi ...
- 备份Ubuntu系统
1.工具:再生龙 2.备份方法:使用再生龙将系统备份(在U盘/boot目录下有很多文件),可以通过这个U盘去装机.将这个U盘生成的文件发送给应用,应用会将其打包生成iso可发布版本: 3.操作步骤:
- [转载]Linux 内核list_head 学习(一)
在Linux内核中,提供了一个用来创建双向循环链表的结构 list_head.虽然linux内核是用C语言写的,但是list_head的引入,使得内核数据结构也可以拥有面向对象的特性,通过使用操作li ...
- HBase之八--(1):HBase二级索引的设计(案例讲解)
摘要 最近做的一个项目涉及到了多条件的组合查询,数据存储用的是HBase,恰恰HBase对于这种场景的查询特别不给力,一般HBase的查询都是通过RowKey(要把多条件组合查询的字段都拼接在RowK ...
- AngularJS:表单
ylbtech-AngularJS:表单 1.返回顶部 1. AngularJS 表单 AngularJS 表单是输入控件的集合. HTML 控件 以下 HTML input 元素被称为 HTML 控 ...
- 【转】gem install libv8 错误
转自:http://my.oschina.net/moks/blog/200344 [摘要]Because libv8 is the interface for the V8 engine used ...
- Apache Geronimo Remote Code Execute Vulnerability
简介: Apache Geronimo 是 Apache 软件基金会的开放源码J2EE服务器,它集成了众多先进技术和设计理念. 这些技术和理念大多源自独立的项目,配置和部署模型也各不相同. Geron ...
- 实验吧CTF题库-密码学(部分)
这里没有key: 打开链接,有一个弹窗 然后就是一个空白网页,右键查看源代码 这里有一串js密文,解密一下,https://www.dheart.net/decode/index.php 得到flag ...
- linux命令-mke2fs
想在磁盘下写东西,必须要先格式化 /////////////////////////////////////////////////////////////////////////////////// ...
- clang: error: linker command failed with exit code 1 (use -v to see invocation) 无法定位的问题
编译出现错误:linker command failed with exit code 1 找到Build settings->Linking->Other Linker Flags,将此 ...