我将Java8的Spring-Boot应用程序部署到Tomcat 8.5中,但是当我使用CURL发送一些请求时,我得到404响应。我不知道我在做什么错。
我对Java并不陌生,但这是我第一次在服务器上设置环境来部署我的应用程序。我关注的博客文章:https://linuxize.com/post/how-to-install-tomcat-9-on-ubuntu-18-04/
唯一的区别是,我在Ubuntu 16.04上安装了Tomcat 8.5,但没有设置管理器界面。
我的Spring-Boot入口点:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
我的pom.xml:
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<groupId>
some.group.id
</groupId>
<artifactId>
server
</artifactId>
<!--<version>-->
<!--1.0-SNAPSHOT-->
<!--</version>-->
<properties>
<commons-lang.version>3.6</commons-lang.version>
<guava.version>25.0-jre</guava.version>
<jwt.version>0.9.0</jwt.version>
<joda-time.version>2.9.9</joda-time.version>
<junit.version>4.12</junit.version>
<mockito.version>2.17.0</mockito.version>
<start-class>some.group.id.Application</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-security</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.199</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
我正在将Tomcat作为服务启动:
Description=Tomcat 8 servlet container
After=network.target
[Service]
Type=forking
User=tomcatuser
Group=tomcatuser
#Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"
Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
JAVA_HOME是在/ etc / environment中设置的,因此被注释掉了。
我将我的应用程序部署到了AWS,并且可以运行。当我从IntelliJ在本地运行它时,它也可以工作。因此,我认为这与我的Tomcat安装有关。另外,我没有任何日志文件,例如catalina.out。
答案 0 :(得分:1)
@lealceldeiro的答案帮助了我
错误是我请求的资源没有应用程序上下文路由的名称。我部署的战争以“ app.war”命名,所以我请求的网址错误:
host-address:8080/resource-uri
正确的URL是:
host-address:8080/app/resource-uri