gpt4 book ai didi

java - tomcat上的Spring Boot WAR文件部署显示错误404

转载 作者:行者123 更新时间:2023-11-28 22:16:01 25 4
gpt4 key购买 nike

我尝试在独立的 Tomcat 7.0.91 上部署 Gradle + Spring Boot 2 + Angular2 应用 WAR 文件。如果我使用提供的 jar 和嵌入式 tomcat 启动应用程序,一切正常,但是当我在独立容器上部署时,当我转到“/springboot”上下文时,它会给我 404:“源服务器没有找到目标资源的当前表示或者是不愿意透露它的存在。”来自 tomcat 的日志没有提供任何有用信息。我尝试了 2 种部署方法,通过在 server.xml 上下文路径和文档库中设置:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="/springboot" docBase="/home/user/SideProjects/springboot-angular2-gradle-war/build/libs"/>
</Host>

其次是在 webapps 目录中“手动”部署 war 文件。

我不确定,但 tomcat 中的文件 context.xml 设置为监视 WEB-INF/web.xml 中的资源,但据我所知,spring boot 不再使用 web.xml,所以也许是这种情况?不幸的是,我发现的每个教程都没有告诉任何关于更改 context.xml 的信息,而且我现在找不到 spring 中的什么资源被认为是部署描述符。

那是我的 build.gradle 文件:

 buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

apply plugin: 'application'
mainClassName = "com.demo.SpringbootAngular2GradleWarApplication"

group = 'com.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

war {
baseName = "demo-spring"
}

repositories {
mavenCentral()
}

configurations {
providedRuntime
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}


def frontendDir = "$projectDir/src/main/frontend"
def frontDistDir = "$frontendDir/dist"

sourceSets {
main {
resources {
srcDirs = ["$frontDistDir", "$projectDir/src/main/resources"]
}
}
}

clean.doFirst {
delete "$frontDistDir"
println "$frontDistDir - cleaned"
}

task buildAngular(type: Exec) {
workingDir "$frontendDir"
inputs.dir "$frontendDir"
commandLine "npm", "run-script", "build"
}

processResources.dependsOn "buildAngular"

主类扩展 servlet 初始值设定项:

 package com.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringbootAngular2GradleWarApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringbootAngular2GradleWarApplication.class);
}

public static void main(String[] args) {
SpringApplication.run(SpringbootAngular2GradleWarApplication.class, args);
}
}

最佳答案

问题是版本不兼容,SpringBoot-2 支持的最低 Tomcat 版本是 8.5.x,以便 el-api 等。实际上,在 webapps 中删除 war 并“手动”重命名它是可行的。

关于java - tomcat上的Spring Boot WAR文件部署显示错误404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52478461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com