如何在Tomcat 7中配置Expires Filter

时间:2014-12-08 07:45:07

标签: tomcat grails filter expires-header

我使用的是grails 2.0.0。我想在tomcat中为静态文件添加expires头。根据tomcat文档,我在web.xml中添加了foll过滤器映射

<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>

添加此内容后,我的应用程序即将出现

我在stacktrace.log中收到了foll错误:

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)

请告诉我是否需要添加任何其他更改。

1 个答案:

答案 0 :(得分:0)

您应该使用asset-pipeline插件及其插件插件。他们积极维护,与Grails很好地集成,并且您将获得的不仅仅是过期标题 - gzipping / minification,捆绑,与less,sass和coffeescript的集成,以及更多我和#39我忘了。