springmvc全注解配置

阅读更多

springmvc全注解配置




  Archetype Created Web Application
  
  
    
        contextClass
        
           org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        
    

    
    
        contextConfigLocation
        com.spring.config.AppConfig
    
  
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
    
        dispatcher
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextClass
            
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            
        
        
        
            contextConfigLocation
            com.spring.config.WebConfig
        
        1
    

    
    
        dispatcher
        /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> messageConverters = new ArrayList>();
		messageConverters.add(mappingJackson2HttpMessageConverter());
		requestMappingHandlerAdapter.setMessageConverters(messageConverters);
		return requestMappingHandlerAdapter;
	}

	@Bean
	public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
		MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
		List supportedMediaTypes = new ArrayList();
		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.zip (57.9 KB)
  • 下载次数: 6

你可能感兴趣的:(springmvc,springmvc,全注解配置)