Reputation: 23607
I am trying to make a simple Spring4 WebService here is a Gist with the basic code
https://gist.github.com/jrgleason/1e23b694e0facc123caa
It seems to start ok but when I access http://localhost:8080/itext
I get a 404 exception. Can someone please help me with what is wrong? Is it because I am using the boot plugin?
Upvotes: 1
Views: 200
Reputation: 23607
The problem is that Spring-Boot does not seem to play nice with the tomcat-plugin (A response that can get it working will steal the star!). As noted above you can reduce to just using the spring-boot...
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")
}
If you do this, however, you will also need to change the Application.java to something like this....
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;
}
Upvotes: 0
Reputation: 31595
Your application is working, check this url: http://localhost:8080/
Change you bean for http://localhost:8080/itext
@RestController
public class GreetingController {
@RequestMapping("/itext")
public String test(){
System.out.println("Test");
return "Test";
}
}
In Spring Boot Tomcat is embedded by default, there is no need to configure tomcat.
Upvotes: 1