【发布时间】:2014-06-09 04:35:26
【问题描述】:
我一直在尝试创建一个使用 Groovy bean builder 的简单 springboot 程序,但我缺少一些东西:
@EnableAutoConfiguration
class MyApplication {
public static void main(String[] args) {
logger.info "Starting MyApplication..."
Object[] sources = [MyApplication.class, new ClassPathResource("bb.groovy")]
SpringApplication.run(sources, args)
}
}
//MyController.groovy
@RestController
class MyController {
ConfigObject configObject
MyService myService
@RequestMapping("/home")
String home() {
return myService.getSomeData()
}
}
//src/main/resources/bb.groovy
beans = {
myService(MyService) {
url = "http://www.spring.io"
}
configObject(ConfigObject) {
new ConfigSlurper().parse("Config.groovy")
}
myController(MyController) {
configObject = ref('configObject')
myService = ref('myService')
}
}
SpringBoot 启动正常,但我在 /home 得到 404。我也没有在启动时看到任何尝试(sys out)从 bb.groovy 加载 bean
从Where to put Groovy bean definitions in a Spring Boot webapp? 的回答中我知道这是可能的,但我一定遗漏了一些东西......
【问题讨论】:
标签: spring-boot