Adding css ResourceHandlers in Spring

Task

CSS to be added to the Spring 4 JSPs

Steps

  1. Create folder called resources\theme1\css under webapp. (I use maven project)
    Adding css ResourceHandlers in Spring.PNG
  2. Create main.css under css folder
  3. Add the resource handler in the Application context config
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "org.grassfield.gaja" })
public class ApplicationContextConfig extends WebMvcConfigurerAdapter {
    @Bean(name = "viewResolver")
    public InternalResourceViewResolver getViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        System.out.println("---> returning viewResolver");
        return viewResolver;
    }
    
    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").
        addResourceLocations("/resources/theme1/").
        setCachePeriod(31556926);
        System.out.println("---> returning resourcehandlers");
    }
}

21BGMCUBE_1904636e

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s