-1

我正在使用 grails 2.0.0。我想在 tomcat 中为静态文件添加过期标头。根据 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 中收到以下错误:

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)

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

4

1 回答 1

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.

于 2014-12-08T19:15:53.257 回答