springmvc全注解配置
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext instead of the default XmlWebApplicationContext --> <context-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </context-param> <!-- Configuration locations must consist of one or more comma- or space-delimited fully-qualified @Configuration classes. Fully-qualified packages may also be specified for component-scanning --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>com.spring.config.AppConfig</param-value> </context-param> <!-- Bootstrap the root application context as usual using ContextLoaderListener --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- Configure DispatcherServlet to use AnnotationConfigWebApplicationContext instead of the default XmlWebApplicationContext --> <init-param> <param-name>contextClass</param-name> <param-value> org.springframework.web.context.support.AnnotationConfigWebApplicationContext </param-value> </init-param> <!-- Again, config locations must consist of one or more comma- or space-delimited and fully-qualified @Configuration classes --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>com.spring.config.WebConfig</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- map all requests for /app/* to the dispatcher servlet --> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> </web-app>
package com.spring.config; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; @Configuration @ComponentScan(basePackages = { "com.spring.web" }) public class WebConfig { /*** * config request handler adapter banxia 2016年4月19日 下午6:45:14 * * @return */ @Bean public RequestMappingHandlerAdapter requestMappingHandlerAdapter() { RequestMappingHandlerAdapter requestMappingHandlerAdapter = new RequestMappingHandlerAdapter(); List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(mappingJackson2HttpMessageConverter()); requestMappingHandlerAdapter.setMessageConverters(messageConverters); return requestMappingHandlerAdapter; } @Bean public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() { MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); List<MediaType> supportedMediaTypes = new ArrayList<MediaType>(); MediaType textMediaType = new MediaType("text","html",Charset.forName("UTF-8")); supportedMediaTypes.add(textMediaType); MediaType jsonMediaType = new MediaType("application","json",Charset.forName("UTF-8")); supportedMediaTypes.add(jsonMediaType); converter.setSupportedMediaTypes(supportedMediaTypes); return converter; } /*** * config request handler mapping handler banxia 2016年4月19日 下午6:48:14 * * @return */ @Bean public RequestMappingHandlerMapping requestMappingHandlerMapping() { return new RequestMappingHandlerMapping(); } /*** * config a view resolver banxia 2016年4月19日 下午6:52:48 * * @return */ @Bean public InternalResourceViewResolver internalResourceViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/jsp/"); resolver.setSuffix(".jsp"); resolver.setViewClass(JstlView.class); return resolver; } }
package com.spring.config; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; /*** * 配置 * * @author banxia * @date 2016年4月19日 下午3:38:18 */ @Configuration @Import(value={ContextConfig.class}) @PropertySource(value={"classpath:app.properties"}) @ComponentScan(basePackages={"com.spring"}) public class AppConfig { }
package com.spring.config; import org.springframework.context.annotation.Configuration; @Configuration public class ContextConfig { }
相关推荐
Spring MVC 全注解配置,吾运行环境:server tomcat8,elcipse,jdk1.8. 注:任何服务器必须是servlet是3.0以上的,否则不能运行,当然也有解决办法,自己百度吧
通过注解配置完全代替web.xml、Spring的xml文件配置,jquery递归遍历后台返回的json对象并进行拼接
03springmvc注解驱动开发的servlet3.0初始化配置类.avi
SpringMVC-配置文档以及其中的说明。 包含使用注解、扫描带注解的包 、使用注解方式配置springMVC的映射器和适配器
Springmvc java注解设置定时任务实例,利用 ScheduledExecutorService 接口实现
Spring+Springmvc+Mybatis注解开发配置,简单实现增删改差,访问路径为 http://localhost:8080/项目名/student/loadList.do,就可以实现效果,
囊括了springMVC的大部分注解,方便了spring的操作,用注解代替配置文件,十分方便,简单易懂
springmvc注解配置。springmvc注解配置。springmvc注解配置。springmvc注解配置。
springMVC整合ibatis,springMVC采用注解方式,配置详细
springMVC配置、注解、列子
springMVC+jdbc(基于注解和标签两种实现方式)
spring+springMVC+BlazeDS注解方式的配置文件.
主要介绍了springmvc注解配置实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
此框架结合了springmvc,hibernate,mybatis3.1,log4j2. 其中mybatis和hibernate只要在spring的配置文件注释一下就可以选择其中一个了。 事务处理,日志设置。所有东西都设置好了。完全满足中小项目直接开发
文档详细的解释了springmvc,有springmvc的配置及注解详解
NULL 博文链接:https://liufangmeng.iteye.com/blog/1971266
本资源主要在与ckeditor,springMVC只有action的注解配置,主要在ckeditor的实现图片的粘贴、上传。
这是一个基于eclipse+springmvc+freemarker+注解的入门例子,是一个war包,import到eclipse就应该可以直接运行,但是确保maven环境到存在;我做为一个入门者,是参照了...