spring-boot/spring-boot-project/spring-boot-cli/samples/http.groovy

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
449 B
Groovy
Raw Normal View History

package org.test
2021-01-21 02:18:00 +08:00
import org.springframework.web.client.RestTemplate;
@Controller
class Example implements CommandLineRunner {
@Autowired
ApplicationContext context
@RequestMapping("/")
@ResponseBody
public String helloWorld() {
return "World!"
}
void run(String... args) {
def port = context.webServer.port
2021-01-21 02:18:00 +08:00
def world = new RestTemplate().getForObject("http://localhost:" + port + "/", String.class);
print "Hello " + world
}
2014-07-29 04:31:22 +08:00
}