【发布时间】:2022-01-22 21:07:16
【问题描述】:
这个Spring example 使用Java 配置来注册一个servlet。为了测试这一点,
- 添加最新的
maven-war-plugin以忽略丢失的web.xml,并且
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>
- 发动战争,然后
- 创建一个
Dockerfile以使用Tomcat,并且
FROM tomcat
COPY example-05-dispatcher-servlet-code-configuration-2-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/
- 构建并运行一个容器,然后
docker build .
docker run -p 8080:8080 -it <image>
- 向
/hello发送请求。
curl -4 -v -XGET http://localhost:8080/hello
但是,tomcat 没有找到控制器,这就是我得到的:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
我做错了什么,我该如何解决?
【问题讨论】:
-
Tomcat 没有找到 servlet 上下文(应用程序),因为它的前缀是
/example-05-dispatcher-servlet-code-configuration-2-1.0-SNAPSHOT/,而不是/。将文件复制为ROOT.war以将您的应用程序部署到服务器的根目录。 -
基本上
tomcat指的是一段时间以来的Tomcat 10。请改用tomcat:9标签。 -
@PiotrP.Karwasz 它确实有效。谢谢!
标签: spring spring-mvc tomcat servlets