Last active
August 29, 2015 13:56
-
-
Save jbrackett/8909259 to your computer and use it in GitHub Desktop.
HelloWorldSpring4Configuration
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.hello; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
@ComponentScan(basePackages = { "com.hello.controller", "com.hello.config" }) | |
public class AppConfig { | |
} |
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.hello.config; | |
import javax.servlet.Filter; | |
import javax.servlet.ServletRegistration.Dynamic; | |
import org.springframework.web.filter.CharacterEncodingFilter; | |
import org.springframework.web.filter.HiddenHttpMethodFilter; | |
import org.springframework.web.filter.HttpPutFormContentFilter; | |
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | |
import com.hello.AppConfig; | |
import com.hello.WebConfig; | |
public class ServletInitializer 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[] { "/" }; | |
} | |
@Override | |
protected void customizeRegistration(Dynamic registration) { | |
registration.setInitParameter("dispatchOptionsRequest", "true"); | |
} | |
@Override | |
protected Filter[] getServletFilters() { | |
CharacterEncodingFilter charFilter = new CharacterEncodingFilter(); | |
charFilter.setEncoding("UTF-8"); | |
charFilter.setForceEncoding(true); | |
return new Filter[] { new HiddenHttpMethodFilter(), charFilter, | |
new HttpPutFormContentFilter() }; | |
} | |
} |
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.hello; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; | |
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |
@EnableWebMvc | |
@Configuration | |
@ComponentScan(basePackages = "com.hello.controller") | |
public class WebConfig extends WebMvcConfigurerAdapter { | |
@Override | |
public void configureDefaultServletHandling( | |
DefaultServletHandlerConfigurer configurer) { | |
configurer.enable(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment