简体   繁体   English

Spring Boot部署WAR

[英]Spring boot deploy WAR

I have a working spring boot application that works fine when I create a JAR file and execute it. 我有一个可以正常工作的spring boot应用程序,当我创建并执行JAR文件时,该应用程序可以正常工作。

But when I follow this tutorial to deploy the WAR on tomcat, I am unable to hit the controllers. 但是,当我按照本教程在Tomcat上部署WAR时,我将无法使用控制器。 I am not sure of the path. 我不确定这条路。 I tried localhost:8080/ appname/controllervalue It doesn't give any response, I don't see an error either. 我尝试了localhost:8080 / appname / controllervalue它没有给出任何响应,我也没有看到错误。

I opened the webapps folder and checked the contents. 我打开了webapps文件夹并检查了内容。 I found a web.xml file and the path there is empty. 我找到了一个web.xml文件,其中的路径为空。 So I tried localhost:8080/ controllervalue , and this also didn't work. 所以我尝试了localhost:8080 / controllervalue ,这也没有用。 Any thing that I am missing? 我有什么想念的吗?

My pom file 我的pom文件

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.intbit</groupId>
<artifactId>ImageRXWebServices</artifactId>
<version>1</version>
<packaging>war</packaging>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.7.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.2.3.RELEASE</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1102-jdbc41</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
        <version>1.2</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.1.8.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.1.8.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.8.RELEASE</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
        <type>jar</type>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <tomcat.version>8.0.3</tomcat.version>
</properties>

<build>
    <plugins>
        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

You need to add WebApplicationInitializer if you are building a war file and deploying it SpringBootServletInitializer 您需要添加WebApplicationInitializer如果你正在建设一个war文件并部署它SpringBootServletInitializer

In sping boot you can use SpringBootServletInitializer 在启动时可以使用SpringBootServletInitializer

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

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

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