Reputation: 1243
I've created a new Spring Boot REST project by following the recipe at http://spring.io/guides/gs/rest-service/ I can get the "Hello World" project to work (it's Java code). The server maps the path "/test" and returns data when I connect to it. However, if I try to create a similar controller in Groovy, it doesn't get mapped. My groovy class lives in src/main/groovy/hello and the Java class from the tutorial lives in src/main/java. I'm building with Gradle 2.4, and I've applied the 'groovy' plugin. The code gets properly compiled, and all classes end up in the same location. The frustrating part is that I had this working in another project months ago, but I don't have access to that source code anymore. To summarize, here's the Java code in src/main/java/hello/GreetingController.java:
@Controller
public class GreetingController {
@RequestMapping("/test")
@ResponseBody
public HttpEntity<String> hello() {
return new ResponseEntity<String>("hello", HttpStatus.OK);
}
}
and this is the corresponding Groovy code in src/main/groovy/hello/TestController.groovy:
@Controller
class TestController {
@RequestMapping("/othertest")
@ResponseBody
HttpEntity<String> hello() {
return new ResponseEntity("hello", HttpStatus.OK)
}
}
I have the groovy-all jar on the classpath as well as the spring-boot-starter-web jar. Everything compiles fine, starts up with no errors, but only the "/test" @RequestMapping from the Java class actually gets mapped. The compiled classes end up in the same directory after building. The code is basically identical between the Java and the Groovy files. What am I missing? BTW, I'm running Spring Boot 1.2.3, Groovy 2.3.9, and Oracle's JDK 1.8.0_25 in case it's relevant.
Upvotes: 1
Views: 1042
Reputation: 1243
Wow, this is another one to chalk up in the category of bizarre stuff. If I explicitly add 'org.springframework:spring-webmvc:4.1.6.RELEASE' to the Gradle dependencies, all of a sudden the Groovy controller starts working. No explanation as to why Java was working without it, or why the Groovy code was not picked up. Oh well.
Upvotes: 1