-1

I'm using grails 2.0.0. I want to add expires header for static files in tomcat. As per the tomcat docs i added the foll filter mapping in web.xml

<filter>
 <filter-name>ExpiresFilter</filter-name>
 <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
  <init-param>
   <param-name>ExpiresDefault</param-name>
   <param-value>access plus 1 year</param-value>
 </init-param>
</filter>

<filter-mapping>
 <filter-name>ExpiresFilter</filter-name>
 <url-pattern>/*</url-pattern>
 <dispatcher>REQUEST</dispatcher>
</filter-mapping>

After adding this , my application is not coming up

I'm getting the foll error in stacktrace.log :

java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
    at org.springframework.context.support.AbstractApplicationContext.containsBean(AbstractApplicationContext.java:1121)
    at org.codehaus.groovy.grails.web.context.GrailsContextLoader$1.run(GrailsContextLoader.java:92)
    at org.codehaus.groovy.grails.lifecycle.ShutdownOperations.runOperations(ShutdownOperations.java:61)
    at org.codehaus.groovy.grails.web.context.GrailsContextLoader.closeWebApplicationContext(GrailsContextLoader.java:142)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:983)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1660)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

Please tell me if i need to add make any other changes.

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
Manisha
  • 775
  • 6
  • 13
  • 30
  • The IllegalStateException error is not related to your question – Konstantin Kolinko Dec 08 '14 at 09:03
  • @KonstantinKolinko I get this error only when i add expire filter in web.xml file. If i remove this filter, then everything works fine. – Manisha Dec 08 '14 at 09:32
  • In param-value, it should be 'access plus 1 years'. 's' was missing in the value. With this change, Expires filter is working – Manisha Dec 08 '14 at 11:00
  • Good that you fond the cause. I filed this into Tomcat Bugzilla, https://issues.apache.org/bugzilla/show_bug.cgi?id=57331 – Konstantin Kolinko Dec 08 '14 at 21:38
  • Still, that IllegalStateException is not the first failure that happens. There should be an earlier error that is logged into localhost.$date.log file. It looks like javax.servlet.ServletException: Exception processing configuration parameter "ExpiresDefault":"access plus 1 year" – Konstantin Kolinko Dec 08 '14 at 21:47

1 Answers1

0

You should use the asset-pipeline plugin and its addon plugins for this. They're actively maintained, very well integrated with Grails, and you'll get a lot more than just expires headers - gzipping/minification, bundling, integration with less, sass, and coffeescript, and more that I'm forgetting.

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156