Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在tomcat部署战争_Tomcat_Spring Boot - Fatal编程技术网

在tomcat部署战争

在tomcat部署战争,tomcat,spring-boot,Tomcat,Spring Boot,我已经在archlinux上安装了tomcat,我尝试了tomcat7和tomcat8。根据包括官方文档在内的多个来源,部署WAR文件就像将其放到webapps文件夹中一样简单,在我的例子中,webapps文件夹是/var/lib/tomcat7/webapps。战争文件被炸开了。但我不知道如何访问我的web应用程序。在localhost:8080上有一个tomcat网页。我还尝试了localhost:8080/war文件名,但这只允许使用HTTP状态404 我用于测试的应用程序是关于sprin

我已经在archlinux上安装了tomcat,我尝试了tomcat7和tomcat8。根据包括官方文档在内的多个来源,部署WAR文件就像将其放到webapps文件夹中一样简单,在我的例子中,webapps文件夹是/var/lib/tomcat7/webapps。战争文件被炸开了。但我不知道如何访问我的web应用程序。在localhost:8080上有一个tomcat网页。我还尝试了localhost:8080/war文件名,但这只允许使用HTTP状态404

我用于测试的应用程序是关于spring boot的第一个指南:

我修改了maven构建文件pom.xml,以便在运行“mvn包”时生成WAR文件:

<?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>org.springframework</groupId>
    <artifactId>gs-spring-boot</artifactId>
    <version>0.1.0</version>

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

    <packaging>war</packaging>

    <dependencies>
        <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>
    </dependencies>

    <properties>
        <java.version>1.7</java.version>
    </properties>


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

</project>

除了修改pom.xml以生成WAR文件外,还需要为web应用程序配置tomcat。这以前是通过web.xml文件完成的。现在,这可以从应用程序本身内部归档。SpringBootServletInitializer和WebApplicationInitializer是要寻找的线索。我发现让I all运行的最简单方法是通过以下方式修改Application.java:

package hello;

import java.util.Arrays;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

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

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

        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }
    }
}

现在我可以看到来自Spring Boot的问候了!在上,gs-spring-boot-0.1.0.war是已部署war文件的名称。

hm。。我希望这是一个简单的…嗯,投反对票?你把按钮弄错了吗?