零配置搭建SpringMVC
来源:互联网 发布:推荐算法有哪几类 编辑:程序博客网 时间:2024/05/18 03:06
第一步,配置DispatcherServlet
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;public class DispatcherServlet extends AbstractAnnotationConfigDispatcherServletInitializer{@Overrideprotected Class<?>[] getRootConfigClasses() {return new Class<?>[] {RootConfig.class};}@Overrideprotected Class<?>[] getServletConfigClasses() {return new Class<?>[] {WebConfig.class};}@Overrideprotected String[] getServletMappings() {return new String[] {"/"};}}
第二步,创建RootConfig
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={"com.shopcz"},excludeFilters={@Filter(type=FilterType.ANNOTATION , value=EnableWebMvc.class)})public class RootConfig {}
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.WebMvcConfigurerAdapter;import org.springframework.web.servlet.view.InternalResourceViewResolver;@Configuration@EnableWebMvc@ComponentScan("com.shopcz")public class WebConfig extends WebMvcConfigurerAdapter{@Beanpublic ViewResolver viewResolver(){InternalResourceViewResolver resolver = new InternalResourceViewResolver();resolver.setPrefix("/WEB-INF/views/");resolver.setSuffix(".jsp");resolver.setExposeContextBeansAsAttributes(true);return resolver;}@Overridepublic void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {configurer.enable();}}
0 0
- 零配置搭建SpringMVC
- springMVC零配置吐槽
- SpringMVC的零配置实现
- 搭建SpringMVC (Java配置)
- 从零单排SpringMVC——SpringMVC项目搭建
- springmvc maven零配置项目部署错误
- 零xml配置SpringMVC返回json数据
- s2ssh零配置环境搭建报错
- 关于SpringMVC框架配置搭建
- springMVC搭建—最少配置
- Servlet3 + SpringMVC零配置:去除所有的xml
- spring4.x 零配置搭建重要的配置类
- springmvc+ibatis框架搭建(xml配置)
- springmvc+mongodb+maven 项目搭建配置
- springmvc+mongodb+maven 项目搭建配置
- SpringMVC框架搭建的几个核心配置
- Spring+Springmvc+Hibernate环境搭建与配置
- springMVC的快速搭建------Java配置
- Android Service完全解析
- 区别getElementByID,getElementsByName,getElementsByTagName
- FreeRTOS系列第7篇---Cortex-M内核使用FreeRTOS特别注意事项
- Android7.0(Android N)适配心得教程
- 数据结构 三:树(Tree)
- 零配置搭建SpringMVC
- oracel 分页查询
- swing JLabel详解以及使用示例
- MAC 青花瓷Charles 抓包工具
- Unity之SerializeField(序列化字段)的一点理解 (2014-05-08 16:32:06)
- C10K问题
- 国际象棋程序设计(四):基本搜索方法
- Http状态码
- FreeRTOS系列第8篇---FreeRTOS内存管理