// Comment WebApplicationInitilizer = > Servlet 3.0
public class WebInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext container) throws ServletException {
// Create the 'root' Spring application Context
AnnotationConfigWebApplicationContext root
= new AnnotationConfigWebApplicationContext();
// Application.java
root.register(Application.class);
// Manager the life cycle if the root application context
container.addListener(new ContextLoaderListener (root));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext
= new AnnotationConfigWebApplicationContext();
// DispatcherContext.java
dispatcherContext.register(DispatcherContext.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new
DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
DispatcherContext.java
@Configuration
@EnableWebMvc
@ImportResource({})
@ComponentScan (basePackages = "com.company.show" ,excludeFilters = {},includeFilters={})
public class DispatcherContext extends WebMvcConfigurerAdapter {
private Environment environment;
// View Resolver Setting
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the
/WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
@Bean
public InternalResourceViewResolver internalResourceViewResolver (){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
// Resource Setting
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
// Exercise
registry.addResourceHandler("/css/**").addResourceLocations("/css/");
registry.addResourceHandler("/images/**").addResourceLocations("/images/");
}
// This same configuration Spring servlet-context.xml
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up
static resources in the ${webappRoot}/resources directory -->
<!-- Handles HTTP GET requests for /resources/** config/DispatcherContext.java
Class=addResourceHandlers Append select choice -->
//<resources mapping="/resources/**" location="/resources/" />
//<resources mapping="/jquery/**" location="/jquery/" />
//<resources mapping="/css/**" location="/css/" />
/* ----------------------------------------------------------------------
<beans:bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize">
<beans:value>10000000</beans:value>
</beans:property>
</beans:bean>
------------------------------------------------------------------------*/<beans:property name="maxUploadSize">
<beans:value>10000000</beans:value>
</beans:property>
</beans:bean>
@Bean
public CommonsMultipartResolver multipartResolver (){
System.out.println("=======>>>>> DispatcherContext multipartResolver Called :");
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(10000000);
return multipartResolver;
}
}
Application.java
@Configuration
@EnableTransactionManagement(mode=AdviceMode.ASPECTJ)
public class Application {}
댓글 없음:
댓글 쓰기