Java Spring启动:IllegalStateException:重复的片段名称Spring\u web

Java Spring启动:IllegalStateException:重复的片段名称Spring\u web,java,spring-boot,spring-mvc,Java,Spring Boot,Spring Mvc,面临非法状态异常:spring启动应用程序中的重复片段名称spring\u web。 浏览了几篇文章,但每个人都提出了与web.xml相关的解决方案。但是在SpringBoot中,我们没有web.xml。什么可能是Spring Boot中最好的解决方案。 对于我的组织,我们需要在war包中构建应用程序。在eclipse中执行时,一切正常。但当尝试在外部Tomcat9服务器中部署时,我们面临着这个问题 这是我的pom.xml <?xml version="1.0" encoding="UTF

面临非法状态异常:spring启动应用程序中的重复片段名称spring\u web。 浏览了几篇文章,但每个人都提出了与web.xml相关的解决方案。但是在SpringBoot中,我们没有web.xml。什么可能是Spring Boot中最好的解决方案。 对于我的组织,我们需要在war包中构建应用程序。在eclipse中执行时,一切正常。但当尝试在外部Tomcat9服务器中部署时,我们面临着这个问题

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.1.8.RELEASE</version>
  <relativePath />
  <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>appname</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>appname</name>
<packaging>war</packaging>
<description>Demo project for Spring Boot</description>
<properties>
  <java.version>1.8</java.version>
</properties>
<dependencies>
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
     <exclusions>
        <exclusion>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
     </exclusions>
  </dependency>
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter</artifactId>
     <exclusions>
        <exclusion>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
     </exclusions>
  </dependency>
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-log4j2</artifactId>
  </dependency>
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-test</artifactId>
     <scope>test</scope>
  </dependency>
  <dependency>
     <groupId>org.springframework</groupId>
     <artifactId>spring-jdbc</artifactId>
     <version>5.1.9.RELEASE</version>
  </dependency>
  <dependency>
     <groupId>log4j</groupId>
     <artifactId>log4j</artifactId>
     <version>1.2.17</version>
  </dependency>
  <!-- exclude tomcat jdbc connection pool, use HikariCP -->
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-jdbc</artifactId>
     <exclusions>
        <exclusion>
           <groupId>org.apache.tomcat</groupId>
           <artifactId>tomcat-jdbc</artifactId>
        </exclusion>
     </exclusions>
  </dependency>
  <!-- exclude tomcat-jdbc, Spring Boot will use HikariCP automatically -->
  <dependency>
     <groupId>com.zaxxer</groupId>
     <artifactId>HikariCP</artifactId>
     <version>3.3.1</version>
  </dependency>
  <!-- For MySQL -->
  <dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>5.1.40</version>
  </dependency>
  <dependency>
     <groupId>com.microsoft.sqlserver</groupId>
     <artifactId>mssql-jdbc</artifactId>
     <version>6.1.0.jre8</version>
  </dependency>
  <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-configuration-processor</artifactId>
     <optional>true</optional>
  </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>
</project>

4.0.0
org.springframework.boot
spring启动程序父级
2.1.8.1发布
com.xyz
appname
0.0.1-快照
appname
战争
SpringBoot的演示项目
1.8
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
弹簧靴起动器
org.springframework.boot
spring启动程序日志记录
org.springframework.boot
spring-boot-starter-log4j2
org.springframework.boot
弹簧起动试验
测试
org.springframework
SpringJDBC
5.1.9.1发布
log4j
log4j
1.2.17
org.springframework.boot
弹簧靴启动器jdbc
org.apache.tomcat
TomcatJDBC
com.zaxxer
希卡里普
3.3.1
mysql
mysql连接器java
5.1.40
com.microsoft.sqlserver
mssql jdbc
6.1.0.jre8
org.springframework.boot
spring引导配置处理器
真的
org.springframework.boot
弹簧启动机tomcat
假如
org.springframework.boot
springbootmaven插件
提前感谢。

org.springframework.boot
 <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-tomcat</artifactId>
弹簧启动机tomcat
您已重复此操作,请删除其中一个

通过这样做,您可以允许复制

 <webAppConfig>
    ...
    <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
    ...
  </webAppConfig>

...
真的
...

您可以尝试将其添加到pom.xml中:

<webAppConfig>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
</webAppConfig>

真的

我不确定您是否正在寻找这个东西,但我有同样的东西,我有一个spring boot应用程序,我正在从中创建war。 我保留了web.xml文件,但其中没有任何内容。这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>Basic</display-name>
    <description>Basic Application</description>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

基本的
基本应用
index.jsp
我正在使用这个类初始化spring中的应用程序

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {ApplicationWebMvcConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] {ApplicationSecurityConfig.class};
    }


}
公共类应用程序初始化器扩展了AbstractAnnotationConfigDispatcherServletInitializer{
@凌驾
受保护类[]getServletConfigClasses(){
返回新类[]{ApplicationWebMvcConfig.Class};
}
@凌驾
受保护的字符串[]getServletMappings(){
返回新字符串[]{”/“};
}
@凌驾
受保护类[]getRootConfigClasses(){
返回新类[]{ApplicationSecurityConfig.Class};
}
}
我可以从Eclipse运行应用程序,也可以在Tomcat中部署它


我没有在应用程序中添加spring boot tomcat依赖项

嗨,谢谢你的回复。但改变这两种情况并没有帮助!!嗨,谢谢你的回复。但改变上述配置并没有起到任何作用