我正在尝试制作一个简单的Spring4 WebService,这是一个带有基本代码的要点
https://gist.github.com/jrgleason/1e23b694e0facc123caa
似乎开始没问题,但是当我访问http://localhost:8080/itext
时,我得到了404异常。有人可以帮我解决有什么问题吗?是因为我使用的是启动插件吗?
答案 0 :(得分:1)
您的申请正常运作,请查看此网址:http://localhost:8080/
更改http://localhost:8080/itext
@RestController
public class GreetingController {
@RequestMapping("/itext")
public String test(){
System.out.println("Test");
return "Test";
}
}
在Spring Boot中默认嵌入Tomcat,不需要配置tomcat。
答案 1 :(得分:0)
问题在于,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;
}