我想我也有类似的问题,但不知道如何修复Tomcat 404错误:源服务器没有找到目标资源的当前表示形式,或者不愿意透露该表示形式的存在
错误图像
我正在尝试使用docker和Tomcat构建简单的hello world spring boot应用程序。我用maven制作了war文件,然后将其放到$CATALINA_HOME/webapps/中,并通过执行[“CATALINA.sh”,“run”]来启动服务器。但我仍然无法访问我的应用程序。
Tomcat状态图像
错误:
HTTP Status 404 – Not Found
Type Status Report
Message /demo/
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.2
Tomcat说,我的应用程序正在运行
我试图提出另一个要求,以避免错误的映射http://localhost:8888/demo/hello http://localhost:8888/hello
主要类别代码:
@SpringBootApplication
@RestController
public class DemoApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello() {
return "Hello";
}
}
Dockerfile
#
# for build
#
FROM maven:3.6.3-jdk-11-slim AS MAVEN_TOOL_CHAIN
COPY pom.xml /tmp/
COPY src /tmp/src/
WORKDIR /tmp/
RUN mvn package
#
# for deploy
#
FROM tomcat:9.0-alpine
MAINTAINER "admin"
USER root
# to get access to admin page
COPY /tomcat-users.xml $CATALINA_HOME/conf/tomcat-users.xml
COPY /settings.xml $CATALINA_HOME/conf/settings.xml
COPY /context.xml /usr/local/tomcat/webapps/manager/META-INF/
WORKDIR $CATALINA_HOME/webapps/
COPY --from=MAVEN_TOOL_CHAIN /tmp/target/demo-0.0.1-SNAPSHOT.war ./demo.war
EXPOSE 8080
CMD ["catalina.sh", "run"]
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<start-class>com.example.demo.DemoApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
雄猫日志
26-Oct-2020 18:47:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/9.0.2
26-Oct-2020 18:47:52.613 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 25 2017 21:08:02 UTC
26-Oct-2020 18:47:52.613 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 9.0.2.0
26-Oct-2020 18:47:52.613 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.19.76-linuxkit
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-1.8-openjdk/jre
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_151-b12
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
26-Oct-2020 18:47:52.615 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
26-Oct-2020 18:47:52.622 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2n 7 Dec 2017]
26-Oct-2020 18:47:52.740 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
26-Oct-2020 18:47:52.756 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Oct-2020 18:47:52.766 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
26-Oct-2020 18:47:52.767 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Oct-2020 18:47:52.768 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 607 ms
26-Oct-2020 18:47:52.795 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
26-Oct-2020 18:47:52.795 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.2
26-Oct-2020 18:47:52.829 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/demo.war]
26-Oct-2020 18:47:54.207 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
26-Oct-2020 18:47:54.332 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo.war] has finished in [1,502] ms
26-Oct-2020 18:47:54.334 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager]
26-Oct-2020 18:47:54.361 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [28] ms
26-Oct-2020 18:47:54.362 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager]
26-Oct-2020 18:47:54.384 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [22] ms
26-Oct-2020 18:47:54.384 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
26-Oct-2020 18:47:54.556 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/examples] has finished in [171] ms
26-Oct-2020 18:47:54.556 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT]
26-Oct-2020 18:47:54.568 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [12] ms
26-Oct-2020 18:47:54.569 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs]
26-Oct-2020 18:47:54.581 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [12] ms
26-Oct-2020 18:47:54.585 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
26-Oct-2020 18:47:54.610 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
26-Oct-2020 18:47:54.612 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1844 ms
26-Oct-2020 18:47:54.292 INFO [main] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath
26-Oct-2020 18:47:54.550 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
26-Oct-2020 18:47:54.550 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
您正在使用的tomcat映像使用jdk8
作为java版本,但是您正在构建的战争使用java11
。因此tomcat没有部署您的应用程序。只要使用tomcat jdk11映像,您的应用程序就应该开始工作。
您可以使用此映像。
FROM tomcat:9.0-jdk11
为了减少漏洞,docker映像中的webapps文件夹将是空的,但是管理器和其他操作所需的文件夹将存储在webapps.dist
文件夹中。因此,如果您需要管理器和主页用户界面,只需将项目从webapps.dist
复制到webapps
目录。
RUN cp -r $CATALINA_HOME/webapps.dist/* $CATALINA_HOME/webapps/
部署过程中出错:部署应用程序[EnterpriseApplication1]时出现异常:UnsupportedClassVersionError:类mn.interactive.module.meta.dao.MetadataDao的主要或次要版本号不受支持,这些版本号大于Java Runtime Environment版本1.7.0_02中的版本号。有关详细信息,请参阅server.log。 将
每次都会出现以下错误!有相同的修复方法吗? 2021-10-07T10:47:31.133956 00:00heroku[路由器]: at=错误代码=H10 desc="应用程序崩溃"方法=GET路径="/"主机=zturlshortener.herokuapp.comrequest_id=c2f90e55-52f5-4955-a1d6-4028456cfddb fwd="103.199.173.
我在试图在Airflow上显示我的本地DAG时遇到了一些问题。 我用Docker部署了Airflow,但是我没有显示我本地计算机上的Dag,它只显示了我在“docker-compose.yaml”文件中设置airflow时出现的“标准”Dag。 我的 dag/日志文件的路径是:C:\用户\taz\文档\工作区(工作区是我拥有 dag 和日志文件夹的文件夹) 这是“docker-compose.ya
当我试图去时,我得到了。 我的控制器: 我也尝试过使用不同的端口。 我的依赖项:SpringWeb、SpringWeb服务、Jersey、SpringDataJPA和H2数据库。 我快要失去它了,所以请帮帮我。
我在将Quarkus 1.10应用程序作为Docker映像部署到Heroku时遇到了问题。 同一个应用程序,使用SpringBoot和一个类似的Docker映像成功引导,但是由于PORT的错误绑定,Quarkus不知何故触发了臭名昭著的R10引导超时错误,即使当我看到引导时间真的很短时(SpringBoot版本为2秒对4.5秒)。如果我在本地启动映像,它可以完美地工作,不会出现任何问题。 我的最终
我有一个Grails(2.5.3版)应用程序,当我通过选项:要部署的WAR文件在Tomcat中部署时,选择WAR文件,会出现以下错误。如果我尝试一个更简单的应用程序(大小、复杂度等),它运行得很好。 但是,如果在从manager运行应用程序时手动将war文件的内容复制到Tomcat路径:pathTomcat/webapps/myApplication,则效果良好。出现任何错误。 错误: Grail