简体   繁体   English

Springboot 应用程序适用于嵌入的 tomcat 但在外部 tomcat 中得到 404

[英]Springboot app works on embbeded tomcat but in external tomcat get 404

I have a project on spring and when i run it on the embbeded tomcat it works so good But the idea is put the project in a external server but when i create the war and i deploy it in tomcat 8 i get 404 even if it is running我在 spring 上有一个项目,当我在嵌入的 tomcat 上运行它时,它工作得很好但是这个想法是将项目放在外部服务器中但是当我创建战争并将其部署在 Z1B359D8754067AA3 时,即使它是 88BEFA04跑步

I have seen that the problem could be in the maven but i tried a lot of things that i saw in other posts and i cant fix it我已经看到问题可能出在 maven 但我尝试了很多我在其他帖子中看到的东西但我无法解决它

i dont knot what else i can do.我不知道我还能做什么。

here is some of my code这是我的一些代码

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

}

my main class already has the serverlet extends i think that its not the problem我的主要 class 已经扩展了 serverlet 我认为这不是问题

<?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.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.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>
  <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
  
    </dependencies>

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

</project>

And here is my pom where i think that could be the problem这是我的pom,我认为这可能是问题所在

I tried to make some exlusion on the springgboot starter web dependecy but it doesnt work我试图排除 springgboot 启动器 web 依赖,但它不起作用

Thats what i see that fix it in other project but not in mine这就是我在其他项目中看到的,但在我的项目中没有

I dont know if could be something on my tomcat but i have tomcat 8 with java 1.8我不知道我的 tomcat 上是否有什么东西,但我有 tomcat 8 和 java 1.8

I suppose that you currently have a web application which is deployed as a spring boot jar application with an embedded server and you want to transform it into a war deployable web application on some already existing tomcat server so that you can have multiple wars (web applications) on some existing tomcat server. I suppose that you currently have a web application which is deployed as a spring boot jar application with an embedded server and you want to transform it into a war deployable web application on some already existing tomcat server so that you can have multiple wars (web applications ) 在一些现有的 tomcat 服务器上。

In this case you must remove the spring-boot dependencies on maven and introduce only spring dependencies (ex spring-web-mvc )在这种情况下,您必须删除 maven 上的spring-boot依赖项并仅引入spring依赖项(例如spring-web-mvc

Then you will have to rewrite some parts of the application so that they conform with those new dependencies.然后,您将不得不重写应用程序的某些部分,以便它们符合那些新的依赖关系。 Your main method for example will be removed.例如,您的主要方法将被删除。

You will need some other configurations as well, as each war file will have it's own application context path, which will distinguish which url's are directed to each web application.您还需要一些其他配置,因为每个war文件都有自己的应用程序上下文路径,这将区分哪些 url 指向每个 web 应用程序。

I deployee spring boot restful app on wildfly what I do is create the class ServletInitializer .我部署 spring 在 wildfly 上启动 restful 应用程序我所做的是创建 class ServletInitializer

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

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

}

I hope this will give you the solution, if not comment me I will try to figure out.我希望这会给你解决方案,如果没有评论我,我会试着弄清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM