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.
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.
- Add the following to your pom.xml
<dependency>
<groupId>org.sevensource</groupId>
<artifactId>wro4spring</artifactId>
<version>X.Y.Z</version>
</dependency>
- 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>
-
Create a wro.xml defining your resources. See https://code.google.com/p/wro4j/wiki/WroFileFormat
-
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;
}
}
-
@Import your Wro4SpringConfiguration in your root application context, ie. the one you asked ContextLoaderListener to use.
-
Enjoy and fork, pull & report, if you wish.