所以我一直在尝试使用java:8基本映像对我的spring-mvc 4应用程序进行docker化:
在docker中运行时,我在以下一行遇到问题,但是在docker之外,一切正常!它与找到我的项目的模板文件有关:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/pages/**").addResourceLocations("classpath:/pages/");
}
请注意,我尝试使用jar文件内部和jarfile外部的模板文件运行. URL调试代码表明它正在查找正确的文件,但是当尝试使用它们时,出现以下异常:
engine_1 | jvm 1 |java.io.FileNotFoundException: class path resource [pages/saga-index.html] cannot be resolved in the file system for resolving its last-modified timestamp
engine_1 | jvm 1 | at org.springframework.core.io.AbstractResource.lastModified(AbstractResource.java:155)
engine_1 | jvm 1 | at org.springframework.core.io.AbstractFileResolvingResource.lastModified(AbstractFileResolvingResource.java:169)
engine_1 | jvm 1 | at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:229)
engine_1 | jvm 1 | at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
engine_1 | jvm 1 | at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
engine_1 | jvm 1 | at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
engine_1 | jvm 1 | at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
engine_1 | jvm 1 | at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
engine_1 | jvm 1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
engine_1 | jvm 1 | at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
engine_1 | jvm 1 | at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
engine_1 | jvm 1 | at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
engine_1 | jvm 1 | at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
engine_1 | jvm 1 | at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
我如何才能解决此异常?为什么我无法获得时间戳?
(更多统计信息)
$docker exec siteconfiguration_engine_1 java -version
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b27)
OpenJDK 64-Bit Server VM (build 25.40-b25,mixed mode)
$docker exec siteconfiguration_engine_1 df -h
Filesystem Size Used Avail Use% Mounted on
none 19G 2.5G 15G 15% /
tmpfs 1004M 0 1004M 0% /dev
shm 64M 0 64M 0% /dev/shm
/dev/sda1 19G 2.5G 15G 15% /etc/hosts
$docker exec siteconfiguration_engine_1 ls -l /decision-engine/etc/pages
total 4
-rw-r--r-- 1 root root 809 Jan 1 1970 saga-index.html
最佳答案
看来,默认情况下,Docker会将文件从未修改的文件丢弃到映像中. Spring已对其模板进行了完整性检查,以查看它们是否曾被更新.执行以下命令解决了我的问题,现在我想到这些代码库之一需要针对它的错误报告.
原文链接:https://www.f2er.com/docker/532559.html$docker exec siteconfiguration_engine_1 bash -c 'touch -m /decision-engine/etc/pages/saga-index.html'
$docker exec siteconfiguration_engine_1 ls -l /decision-engine/etc/pages
total 4
-rw-r--r-- 1 root root 810 Mar 30 02:39 saga-index.html
以下是@Rannick创建的错误:
> https://github.com/docker/docker/issues/11916
> https://jira.spring.io/browse/SPR-12862