【问题标题】:Springboot war deployed on external tomcat but 404Spring Boot 战争部署在外部 tomcat 但 404
【发布时间】:2022-01-05 19:10:35
【问题描述】:

我在 tomcat 上有一个项目,它可以在 spring 上运行,但是当我尝试部署在外部 tomcat 上时,出现 404 错误

我尝试了很多东西,但我无法解决它

我的主要课程

我看到了

@SpringBootApplication
public class RApplication extends SpringBootServletInitializer implements CommandLineRunner {
        @Resource
     // FileStorageService storageService;
        
        FileStorageService storageService;
    public static void main(String[] args) {
        SpringApplication.run(RApplication.class, args);
    }
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
          return builder.sources(RApplication.class);
      }
      @Override
      public void run(String... arg) throws Exception {
        storageService.deleteAll();
        storageService.init();
      }

}

还有我的 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.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.r</groupId>
    <artifactId>RD</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>RDrone</name>
    <description>Portal Web</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery-validation</artifactId>
            <version>1.19.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>font-awesome</artifactId>
            <version>5.13.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>4.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>popper.js</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.40</version>
        </dependency>
        <dependency>
    <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    <version>1.4</version>
  </dependency>
    </dependencies>

    <build>
     <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我已经尝试过在 Spring Web 依赖项上创建排除项 并在我的 maven 上创建 servlet 依赖,但它不起作用

我认为问题出在我的项目上,但我不知道它是否可能是我的 tomcat 上的问题

【问题讨论】:

    标签: spring-boot maven tomcat


    【解决方案1】:

    如果您正在创建 Spring Boot 应用程序,Tomcat 服务器是嵌入式的,这意味着您无需担心将 JAR/WAR 文件部署到外部 Tomcat 服务器上。您的问题在这里似乎无效,您能否详细说明您到底要做什么?您的 POM.xml 具有启动 Spring Boot 应用程序所需的更多依赖项!

    【讨论】:

    • 是的,我知道 spring 嵌入了服务器,但我想将应用程序部署在外部服务器中我的 pom 可能是依赖关系的问题?
    猜你喜欢
    • 2015-10-28
    • 2019-03-21
    • 2019-03-23
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 2021-01-26
    相关资源
    最近更新 更多