在Jetty上部署Spring Boot Application会产生404

时间:2016-08-12 18:07:31

标签: java spring spring-boot jetty

我有一个Spring Boot应用程序,它运行在服务器上的独立Jetty实例上。我创建一个WAR文件并将其部署到Jetty,一切正常。我的服务有一个端点/healthz,它返回一个字符串,就是这样。

我的代码如下所示:

src
  |-main
     |-java
        |-com.test
           |-controllers
              |-Health.java
           |-ServletInitalizer.java
           |-TestApplication.java

TestApplication.java:

package com.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TenderfootApplication {

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            System.out.println("LAUNCHED INTERNAL");
        }
        SpringApplication.run(TenderfootApplication.class, args);
    }
}

ServletInitalizer.java:

package com.test;

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

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        for (int i = 0; i < 10; i++) {
            System.out.println("LAUNCHED EXTERNAL");
        }
        return application.sources(TenderfootApplication.class);
    }
}

Health.java:

package com.test.controllers;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Health {
    @RequestMapping(value = "/healthz", method = RequestMethod.GET)
    public String healthz() {
        return "running fine";
    }
}

我的build.gradle:

buildscript {
    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'


war {
    baseName = 'test'
    archiveName = 'test.war'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
    compile.exclude module: "spring-boot-starter-tomcat"
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude module: 'spring-boot-starter-logging'
    }
    compile("org.springframework.boot:spring-boot-starter-jetty")
    compile("org.springframework.boot:spring-boot-starter-log4j2")
    runtime('org.postgresql:postgresql')
    providedRuntime("org.springframework.boot:spring-boot-starter-jetty")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR4"
    }
}

当我在jetty 8.1.3上运行时,我的端点上有404。自从我生成testserver.war后,我尝试查询导致404的localhost:8080/testserver/healthz。我找到了这个日志,但不知道如何解释它:

16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/tenderfoot/healthz]
16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /healthz
16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/healthz]
16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/healthz] are [/**]
16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/healthz] are {}
16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/healthz] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@6b07d8a1] and 1 interceptor
16:05:28.554 [qtp1273958371-40] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/tenderfoot/healthz] is: -1
16:05:28.558 [qtp1273958371-40] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
16:05:28.558 [qtp1273958371-40] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request

可能导致我的404错误的原因是什么?

0 个答案:

没有答案