当前位置: 首页 > 知识库问答 >
问题:

Spring Bootwar文件可与嵌入式Tomcat一起工作,但不能与独立的Tomcat一起工作

宗政卓
2023-03-14

我想从Spring Boot应用程序创建一个war文件,我可以将其部署到独立的Tomcat容器中,而不是使用嵌入式容器。

我可以创建war文件,并使用“java-jar pdfjs-annotator.war”单独运行它,它工作得很好。

我使用Gradle BootrePackage(使用Gradle、Tomcat7、Java1.7)构建了应用程序。

但当我将war文件部署到独立的Tomcat并启动它时,根据日志显示,应用程序似乎没有错误地启动,但我无法访问任何资源,控制器URL也无法工作。

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

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot' 
apply plugin: 'io.spring.dependency-management' 
apply plugin: 'war'


war {
    baseName = 'pdfjs-annotator'
    version = '1.0.0-SNAPSHOT'
}

allprojects {
    apply plugin: 'java'
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-web")
    runtime("mysql:mysql-connector-java")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    compile ('org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final')
}


eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}
@EnableJpaRepositories
@SpringBootApplication
public class PdfAnnotator extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(PdfAnnotator.class);
    }

}

当我研究爆炸的战争时,我确实看到了以下meta-inf/manifest.mf:

Manifest-Version: 1.0
Start-Class: com.mypackage.pdfcomment.PdfAnnotator
Spring-Boot-Version: 1.2.3.RELEASE
Main-Class: org.springframework.boot.loader.WarLauncher

gradle构建过程通常生成两个war工件,一个名为.war和一个名为.war.originate-war是一个保存正确的manifest.mf条目的工件,它是我用来部署到独立的Tomcat的工件。

少了什么?我已经查过其他问题了:

  • 没有嵌入tomcat的Spring Boot大战
  • 在Tomcat中部署WAR

共有1个答案

陆敏学
2023-03-14

我有这个问题。这是因为我的应用程序是用Java1.8构建的,而Tomcat是用1.7运行的。一切似乎都部署妥当,没有任何错误。我只是得到了一个404试图击中我的服务,否则在嵌入式tomcat服务器上是很好的。我花了很长时间才弄明白,但这只是在安装Tomcat时升级java的一个例子。

 类似资料:
  • 当在嵌入了tomcat的spring boot中运行代码时,Spring cloud consul可以像预期的那样工作。 当我们在独立的tomcat上部署代码时,它不起作用。似乎有一个Web服务器上启动领事服务注册。仅当我们在带有嵌入式 tomcat 的Spring启动内运行代码时,才会触发此事件。 https://github.com/spring-cloud/spring-cloud-cons

  • 在我的Laravel应用程序中,我需要定期使用Guzzle将数据发送到API。 API使用承载令牌进行身份验证,并请求和接受原始JSON。为了进行测试,我使用Postman访问了API,一切都工作得很好。

  • 基于这个问题的答案-[如何将Jersey REST Web服务添加到嵌入式tomcat中? 这似乎对其他人有用。是否有人有一个GIT项目或maven项目所需的依赖项列表,该项目将用于嵌入式tomcat(v8. x或更新版本)和泽西v2. x的REST终结点? 这是POM文件 http://maven.apache.org/xsd/maven-4.0.0.xsd" 下面是启动tomcat的类: 公共

  • 错误:org.apache.hive.service.cli.hivesqlexception:处理语句时出错:失败:执行错误,从org.apache.hive.service.cli.operation.operation.toSqlexception(operation.java:380)(org.apache.hive.service.cli.operation.sqloperation.r

  • 3)使用REST客户端 将response_resclient.code 对于1和2,两者都是正确的。它们都返回状态201,登录成功,但使用3-REST_Client失败。状态为404 REST_Client: 对于Rest-client gem,它在向mysite.vn发送post请求后返回404错误,代码为443。我对这个案子没有理想。请你帮我解释一下这个案子好吗。如何用REST客户端纠正这个

  • 我正在编写一个Web项目,它使用了Apache Tomcat 5.0和JDK 1.4.2之上的Spring框架2.5。 当Tomcat启动时,它从未加载Spring。 Web.xml如下: "web-Application ationContext.xml"就像: 控制台提供了以下日志堆栈跟踪: 严重:配置类org的应用程序侦听器时出错。springframework。网状物上下文ContextL