【发布时间】:2014-12-08 07:45:06
【问题描述】:
我正在使用 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 中收到 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)
如果我需要添加任何其他更改,请告诉我。
【问题讨论】:
-
IllegalStateException 错误与您的问题无关
-
@KonstantinKolinko 我只有在 web.xml 文件中添加过期过滤器时才会收到此错误。如果我删除此过滤器,那么一切正常。
-
在param-value中,应该是'access plus 1 years'。值中缺少“s”。通过此更改,Expires 过滤器正在工作
-
很高兴你喜欢这个事业。我将此提交到 Tomcat Bugzilla,issues.apache.org/bugzilla/show_bug.cgi?id=57331
-
不过,IllegalStateException 并不是第一次发生的失败。应该有一个较早的错误记录到 localhost.$date.log 文件中。貌似是javax.servlet.ServletException: 异常处理配置参数"ExpiresDefault":"access plus 1 year"
标签: tomcat grails filter expires-header