繁体   English   中英

Spring4 Boot WebService Controller不适用于Gradle Tomcat插件

[英]Spring4 Boot WebService Controller not working with Gradle Tomcat Plugin

我正在尝试制作一个简单的Spring4 WebService,这里是基本代码的要点

https://gist.github.com/jrgleason/1e23b694e0facc123caa

它似乎可以正常启动,但是当我访问http://localhost:8080/itext了404异常。 有人可以帮我解决什么问题吗? 是因为我正在使用启动插件吗?

您的应用程序正在运行,请检查以下URL: http://localhost:8080/

将您的bean更改为http://localhost:8080/itext

@RestController
public class GreetingController {
    @RequestMapping("/itext")
    public String test(){
        System.out.println("Test");
        return "Test";
    }
}

在默认情况下,在Spring Boot Tomcat中是嵌入式的,不需要配置tomcat。

问题是Spring-Boot似乎在tomcat-plugin 上不能很好地工作(可以使它工作的响应会抢走它!) 如上所述,您可以减少到仅使用弹簧靴...

buildscript {
  repositories {
    mavenLocal()
    mavenCentral()
  }
  dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.1.RELEASE")
  }
}
apply plugin: 'war'
apply plugin: 'spring-boot'
war { baseName='itext' }
repositories {
  mavenLocal()
  mavenCentral()
}
dependencies {
  compile("org.springframework.boot:spring-boot-starter-web")
  providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
  testCompile("org.springframework.boot:spring-boot-starter-test")
}

但是,如果执行此操作,则还需要将Application.java更改为类似以下内容。

package com.gleason.itext;
import java.util.Arrays;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

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

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

    private static Class<Application> applicationClass = Application.class;
}

暂无
暂无

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

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