代码之家  ›  专栏  ›  技术社区  ›  The Old County

Java Spring Boot-war文件未部署在Tomcat Apache上

  •  1
  • The Old County  · 技术社区  · 7 年前

    我已经构建了war文件,但当我尝试部署它时,它的结构似乎不正确,并生成了一个404试图查看该项目。

    enter image description here enter image description here

    • 我的pom

      http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0

      <groupId>org.springframework</groupId>
      <artifactId>gs-spring-boot</artifactId>
      <version>0.1.0</version>
      <packaging>war</packaging>
      
      <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>1.5.7.RELEASE</version>
      </parent>
      
      <dependencies>
          <!-- web -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
          <!-- test -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-test</artifactId>
              <scope>test</scope>
          </dependency>
          <!-- Spring Security -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-security</artifactId>
          </dependency>
          <!-- jpa -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-data-jpa</artifactId>
          </dependency>
          <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api -->
          <dependency>
              <groupId>org.hibernate.javax.persistence</groupId>
              <artifactId>hibernate-jpa-2.0-api</artifactId>
              <version>1.0.1.Final</version>
          </dependency>
          <!-- mysql connector -->
          <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
          </dependency>
          <!-- mail service -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-mail</artifactId>
          </dependency>       
          <!-- hot swapping, disable cache for template, enable live reload -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-devtools</artifactId>
              <optional>true</optional>
              <scope>provided</scope>
          </dependency>
          <!-- freemarker template -->
          <dependency>
              <groupId>org.freemarker</groupId>
              <artifactId>freemarker</artifactId>
              <version>2.3.23</version>
          </dependency>
          <!-- json simple -->
          <dependency>
              <groupId>com.googlecode.json-simple</groupId>
              <artifactId>json-simple</artifactId>
              <version>1.1.1</version>
          </dependency>
      
          <!-- tag::actuator[] -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-actuator</artifactId>
          </dependency>
          <!-- end::actuator[] -->
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-configuration-processor</artifactId>
              <optional>true</optional>
          </dependency>
          <dependency>
              <groupId>com.h2database</groupId>
              <artifactId>h2</artifactId>
              <version>1.4.194</version>
              <scope>test</scope>
          </dependency>
      </dependencies>
      
      <properties>
          <java.version>1.8</java.version>
      </properties>
      
      <build>
          <plugins>
              <plugin>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
              </plugin>
              <plugin>
                  <artifactId>maven-failsafe-plugin</artifactId>
                  <executions>
                      <execution>
                          <goals>
                              <goal>integration-test</goal>
                              <goal>verify</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </build>
      

    4 回复  |  直到 7 年前
        1
  •  7
  •   The Old County    7 年前

    要使Spring Boot作为war部署,您需要重新配置应用程序类。

    https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html#howto-create-a-deployable-war-file

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class, args);
        }
    
    }
    

    添加

    <packaging>war</packaging>
    

    在使用maven时,我还添加了依赖项。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    

        2
  •  1
  •   user4856296 user4856296    7 年前

    Java Spring Boot-war文件未部署在Tomcat Apache上

    Spring Boot内置应用程序。jar包含应用服务器。

    Spring Boot 旨在使创建Spring驱动的、生产级应用程序和服务变得简单,同时减少麻烦。它对Spring平台采取了一种固执己见的观点,以便新用户和现有用户能够快速获得他们需要的信息。您可以使用它创建独立的Java应用程序,这些应用程序可以使用Java-jar或更传统的WAR部署启动。我们还提供了一个运行spring脚本的命令行工具。

    https://spring.io/blog/2013/08/06/spring-boot-simplifying-spring-for-everyone

    因此,您不需要再次在Apache Tomcat应用服务器中部署。 就像简单的java一样运行它。jar文件。

    nohup java -jar app.jar &
    
        3
  •  0
  •   Acewin    7 年前

    Spring Boot web项目的一个工作示例 Spring Boot WebApp as WAR

    您需要将其修改为WAR,并检查WEB-INF的内容是否正确。

    打包为war的Spring boot应用程序不是为了单独部署到Tomcat中,而是直接通过Spring boot应用程序(通过main方法)运行。您需要进行测试,但根据我的理解,如果有人建议您在tomcat中部署它,那么您需要通知他们他们需要常规的Web应用程序,而不是 SpringBoot应用程序。

    每个SpringBoot应用程序都运行自己的容器。

        4
  •  0
  •   B. Pleshakov    7 年前

    根据 Traditional deployment page 你必须添加依赖项

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>