在Tomcat上部署Spring引导文件 [英] Spring boot war file deploy on Tomcat

查看:169
本文介绍了在Tomcat上部署Spring引导文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring Boot 1.2.4.RELEASE与 gs-rest-service 源文件。
我得到:

  127.0.0.1  -   -  [18 / Jun / 2015:09:59:25 +0300 ]GET /gs-rest-service-0.1.0/ HTTP / 1.1404 1021 

在Tomcat日志中没有其他例外。



我已经阅读了相关问题,但我的测试没有运行。
部署到Tomcat的Spring Boot War



我已阅读 howto-create-a-deployable-war 包装可执行jar和war文件



也许我想念一些东西。 >

我的来源:



1.pom.xml

 <?xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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-rest-service< / artifactId>
< version> 0.1.0< / version>
< packaging> war< / packaging>

< properties>
< start-class> hello.Application< / start-class>
< java.version> 1.8< / java.version>
< / properties>


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

< dependencies>
<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
< / dependency>

<依赖关系>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< scope>已提供< / scope>
< / dependency>
< / dependencies>

< build>
< plugins>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.3.2< / version>
< configuration>
< showDeprecation> true< / showDeprecation>
< / configuration>
< / plugin>
< / plugins>
< / build>

< repositories>
< repository>
< id> spring-releases< / id>
< url> https://repo.spring.io/libs-release< / url>
< / repository>
< / repositories>
< pluginRepositories>
< pluginRepository>
< id> spring-releases< / id>
< url> https://repo.spring.io/libs-release< / url>
< / pluginRepository>
< / pluginRepositories>
< / project>

2.Application.java

  package hello; 

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

@SpringBootApplication
public class应用程序扩展SpringBootServletInitializer {

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

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

文件Greeting.java和GreetingController.java不会更改。

解决方案

刚刚尝试过,可以再现完全相同的行为。



愚蠢的声音,很可能你是在Java 1.7 JRE(推测)下运行你的外部tomcat,而编译你的代码为1.8(我们从你的pom知道)。



奇怪的是,没有错误,应用程序出现在经理应用程序中,但是当您尝试访问该应用程序时,您会收到一个404。



确认这一点的一种方法是查看你的tomcat日志输出。你看到Spring Boot横幅吗?可能不是。


I use Spring Boot 1.2.4.RELEASE with gs-rest-service source file. I got:

127.0.0.1 - - [18/Jun/2015:09:59:25 +0300] "GET /gs-rest-service-0.1.0/ HTTP/1.1" 404 1021

There are no other exceptions in Tomcat logs.

I have read related questions, but my test doesn't run. Spring Boot War deployed to Tomcat

I have read howto-create-a-deployable-war and Packaging executable jar and war files.

Maybe I miss something.

My source:

1.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-rest-service</artifactId>
    <version>0.1.0</version>
    <packaging>war</packaging>

    <properties>        
        <start-class>hello.Application</start-class>
        <java.version>1.8</java.version>
    </properties>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.4.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-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

2.Application.java

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
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) {
        SpringApplication.run(Application.class, args);
    }
}

Files Greeting.java and GreetingController.java are not changed.

解决方案

Just tried this here, and could reproduce the exact same behaviour.

As silly as it sounds, most likely you are running your external tomcat under a Java 1.7 JRE (speculation), while having compiled your code against 1.8 (we know this from your pom).

Strangely, there is no error, and the app appears in the manager app, but then you get a 404 when you're trying to access it.

One way to confirm this is to look at your tomcat log output. Do you see the Spring Boot banner? Probably not.

这篇关于在Tomcat上部署Spring引导文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆