我在tomcat 9上部署spring引导war时,已经尝试了许多解决方案,比如清理项目和在堆栈溢出中找到的所有可能的解决方案,但是没有什么效果,其中一个在web.xml中提供绝对排序,但是它是一个春季引导应用程序,所以我不需要使用web.xml file.The应用程序,所以我一直在与本地主机完美地搜索,当我在server.Below上部署war文件时,问题就出现了。
23-Aug-2019 04:03:25.139 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/apache-tomcat/webapps/LoopServer.war]
23-Aug-2019 04:03:27.100 SEVERE [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/opt/apache-tomcat/webapps/LoopServer.war]
java.lang.IllegalStateException: Error starting child
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:716)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1849)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1620)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:305)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1144)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1346)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1350)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1328)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/LoopServer]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
... 25 more
Caused by: java.lang.IllegalArgumentException: More than one fragment with the name [spring_web] was found. This is not legal with relative ordering. See section 8.2.2 2c of the Servlet specification for details. Consider using absolute ordering.
at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2257)
at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2215)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1127)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5048)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 26 more
23-Aug-2019 04:03:27.103 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/apache-tomcat/webapps/LoopServer.war] has finished in [1,964] ms
下面是我的等级依赖合并
group 'com.lss.loopserver'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.2.RELEASE'
repositories {
mavenCentral()
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("javax.servlet:javax.servlet-api:4.0.1")
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'LoopServer'
version = '0.0.1'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
configurations {
providedRuntime
compile.exclude module: 'spring-boot-starter-tomcat'
all*.exclude module: 'spring-boot-starter-logging'
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'com.zaxxer', module: 'HikariCP'
implementation('org.springframework.cloud:spring-cloud-starter-oauth2')
implementation('org.springframework.boot:spring-boot-starter-security') {
exclude group: 'org.springframework', module: 'spring-aop'
implementation('org.springframework.boot:spring-boot-starter-aop')
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
providedCompile('javax.servlet:javax.servlet-api:4.0.1')
compile('javax.el:javax.el-api:3.0.0')
compile('javax.validation:validation-api:2.0.1.Final')
compile('org.hibernate:hibernate-validator:5.4.1.Final')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
implementation('javax.inject:javax.inject:1')
implementation('mysql:mysql-connector-java:6.0.6')
implementation('joda-time:joda-time:2.10.2')
implementation ('com.google.code.gson:gson:2.8.1')
implementation group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
implementation ('org.apache.commons:commons-io:1.3.2')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testImplementation('org.springframework.boot:spring-boot-starter-test')
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.RC2"
bootRun {
sourceResources sourceSets.main
}
application.yml:
server:
port: 8080
servlet:
context-path: /LoopServer
spring:
datasource:
url: jdbc:mysql://${db.host:localhost}:${db.port:3306}/${db.name:loopschool}?useSSL=false
username: ${db.uid:root}
password: ${db.pwd:password}
driver-class-name: com.mysql.cj.jdbc.Driver
tomcat:
test-while-idle: true
validation-query: SELECT 1
type: com.mysql.cj.jdbc.MysqlDataSource
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
new_generator_mappings: false
format_sql: true
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
ddl-auto: validate
open-in-view: false
application:
name: LoopServer
default-domain: LoopServer
main:
allow-bean-definition-overriding: true
devtools:
livereload:
enabled: false
logging:
level:
hibernate:
SQL: DEBUG
type:
descriptor:
BasicBinder: TRACE
主修班:
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class Main extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Main.class);