Skip to content

shenxiuqiang/wro4spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wro4spring

Configuration support for using wro4j with Spring MVC.

wro4spring serves as the base for wro4spring-thymeleaf-dialect, a Thymeleaf dialect making it easy to integrate wro4j.

Overview

wro4spring provides configuration support for using the excellent wro4j resources optimizer with Spring. In detail, it provides:

  • @Configuration support class with sensible defaults to get you started quickly within a couple of lines.
    • all defaults can be easily customized and overriden
    • allows for easy distinction between development and production mode and their respective settings.
  • WroModelAccessor, which allows you to easily retrieve a groups resources
  • GroupPerFile-GroupExtractor and -Transformer - in development mode, wro4spring alters the model and creates a group per resource. This allows you to use wro4j filters without minimization and without concatenation.

Getting started

  1. Add the following to your pom.xml
<dependency>
      <groupId>org.sevensource</groupId>
      <artifactId>wro4spring</artifactId>
      <version>X.Y.Z</version>
</dependency>
  1. Add the following to your web.xml
<filter>
      <filter-name>wroFilter</filter-name>
      <filter-class>org.sevensource.wro4spring.DelegatingWroFilterProxy</filter-class>
</filter>
<filter-mapping>
      <filter-name>wroFilter</filter-name>
      <url-pattern>/static/bundles/*</url-pattern>
</filter-mapping>
  1. Create a wro.xml defining your resources. See https://code.google.com/p/wro4j/wiki/WroFileFormat

  2. Create a @Configuration class - all configurable aspects and the inner workings are contained in DefaultAbstractWro4SpringConfiguration and its superclasses.

@Configuration
public class Wro4SpringConfiguration extends DefaultAbstractWro4SpringConfiguration {
      @Override
      protected String getWroFile() {
        return super.getWroFile();
      }
	
      @Override	
      public WroDeliveryConfiguration wroDeliveryConfiguration() {
        WroDeliveryConfiguration configuration = new WroDeliveryConfiguration();
        configuration.setDevelopment(isDevelopment());
        configuration.setUriPrefix("/static/bundles/");
        //configuration.setCdnDomain("cdn.foo.com");
        return configuration;
  	  }
	
      @Override
      protected boolean isDevelopment() {
        return true;
      }
}
  1. @Import your Wro4SpringConfiguration in your root application context, ie. the one you asked ContextLoaderListener to use.

  2. Enjoy and fork, pull & report, if you wish.

About

Configuration aid to use wro4j with spring

Resources

Stars

Watchers

Forks

Packages

No packages published