我想从Spring Boot应用程序创建一个war文件,该文件可以部署到独立的Tomcat容器中,而不使用嵌入式容器。
我可以创建war文件并使用自己运行它,"java -jar pdfjs-annotator.war"
并且效果很好。
我使用gradle bootRepackage
(使用Gradle,Tomcat7,Java 1.7)构建了应用程序。
但是,当我将war文件部署到独立的Tomcat上并启动它时,该应用程序似乎根据日志启动而没有错误,但是我无法访问任何资源,也无法运行控制器的url。
例如,我的index.html是src / main / resources / static / index.html下的静态html页面,通常可以通过localhost:8080 / index.html调用它,但是当部署到独立的Tomcat时,该页面不能通过相同的URL传递(然后在WEB-INF / classes / static / index.html中的war文件中)。而且,任何种类的控制器映射似乎都不起作用。我收到了404错误。
build.gradle:
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.original-.war是保存正确MANIFEST.MF条目的工件,也是我用来部署到独立Tomcat的工件。
缺少了什么?我已经在这里检查了其他问题:
以及Spring Boot文档,但找不到任何提示。
* ===更新=== *
我安装了全新的Tomcat7,在其中部署了war文件,一切正常。似乎与我运行的Tomcat实例/配置有关。不知道到底是什么问题,但是我不会再去检查它了,因为它现在可以在新的Tomcat上正常工作了。
该项目实际上是正确设置的,事实证明问题出在我正在运行的Tomcat实例上。配置或jar可能有问题。该实例已经存在很长时间了,也许随着时间的推移事情变得一团糟。
现在,安装了全新的Tomcat7实例,战争就可以了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句