Created
September 26, 2013 05:58
-
-
Save CrisLi/6710358 to your computer and use it in GitHub Desktop.
Spring MVC java based config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xerox.efui.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.EnableWebMvc; | |
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |
import org.springframework.web.servlet.view.InternalResourceViewResolver; | |
import org.springframework.web.servlet.view.JstlView; | |
@Configuration | |
@EnableWebMvc | |
@ComponentScan(basePackages = "org.chris.demo") | |
public class WebConfig extends WebMvcConfigurerAdapter { | |
@Override | |
public void addResourceHandlers(final ResourceHandlerRegistry registry) { | |
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); | |
} | |
@Bean | |
public ViewResolver viewResolver() { | |
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); | |
viewResolver.setViewClass(JstlView.class); | |
viewResolver.setPrefix("/WEB-INF/views/"); | |
viewResolver.setSuffix(".jsp"); | |
return viewResolver; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xerox.efui.config; | |
import org.dozer.DozerBeanMapper; | |
import org.dozer.Mapper; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.ComponentScan.Filter; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.PropertySource; | |
import org.springframework.core.env.Environment; | |
import org.springframework.stereotype.Controller; | |
@Configuration | |
@ComponentScan(basePackages = "org.chris.demo", excludeFilters = { | |
@Filter({ | |
Configuration.class, Controller.class | |
}) | |
}) | |
@PropertySource(value = "classpath:/config/appConfig.properties") | |
public class AppConfig { | |
@Autowired | |
private Environment environment; | |
@Bean | |
public Mapper mapper() { | |
return new DozerBeanMapper(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.xerox.efui.config; | |
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | |
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | |
@Override | |
protected Class<?>[] getRootConfigClasses() { | |
return new Class<?>[] { | |
AppConfig.class | |
}; | |
} | |
@Override | |
protected Class<?>[] getServletConfigClasses() { | |
return new Class<?>[] { | |
WebConfig.class | |
}; | |
} | |
@Override | |
protected String[] getServletMappings() { | |
return new String[] { | |
"/" | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment