SpringFramework Resource java Configuratiin



Webinitializer.java

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
    @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/");
    }

}

Application.java

@Configuration
@EnableTransactionManagement(mode=AdviceMode.ASPECTJ)
public class Application {
}


댓글

이 블로그의 인기 게시물

jquery css

Struts2의 작동 원리

JSP/Servlet 한글 깨짐 처리 ?