Sr. Staff Platform Engineer @ GrubHub
CJUG/CKUG Co-Organizer
ktlint-gradle & spring-funk Maintainer
wakingrufus
@wakingrufus@bigshoulders.city
@SpringBootApplication
@EnableWebMvc
public class MyApplication {
}
@Service
public class MyBusinessLogic {
public String doSomething();
}
@RestController
public class MyController {
private final MyBusinessLogic service;
@Autowired
public MyController(MyBusinessLogic service) {
this.service = service;
}
@GetMapping(path = "/ping")
public String get() {
return service.doSomething();
}
}
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableWebMvc
public class MyApplication {
@Bean
MyBusinessLogic myBusinessLogic() {
return MyBusinessLogic();
}
@Bean
MyController myController(MyBusinessLogic myBusinessLogic) {
return MyController(myBusinessLogic);
}
}
public class MyBusinessLogic {
public String doSomething();
}
@RestController
public class MyController {
private final MyBusinessLogic service;
public MyController(MyBusinessLogic service) {
this.service = service;
}
@GetMapping(path = "/ping")
public String get() {
return service.doSomething();
}
}
val beans = beans {
bean<MyBusinessLogic>()
bean<MyBusinessLogicWithInjection> {
MyBusinessLogicWithInjection(ref())
}
bean<MyBusinessLogicWithInjectionByName>("beanName") {
MyBusinessLogicWithInjectionByName(ref("name"))
}
}
class MyBusinessLogic {
fun doSomething(request: ServerRequest): ServerResponse
}
val myRoutes(service: MyBusinessLogic) = router {
GET("/ping", service::doSomething)
POST("/ping", service::doSomethingElse)
}
val myRoutes(service: MyBusinessLogic) = router {
GET("/ping", service::doSomething)
}
val beans = beans {
bean<MyBusinessLogic>()
bean(::myRoutes)
}
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableWebMvc
open class MyApplication
: ApplicationContextInitializer<GenericApplicationContext> {
override fun initialize(context: GenericApplicationContext) {
beans.initialize(context)
}
}
class MyBusinessLogic {
public String doSomething();
}
val myRoutes(service: MyBusinessLogic) = router {
GET("/ping", service::doSomething)
}
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableWebMvc
@Import(SampleBeanRegistrar::class)
open class MyApplication {
}
class MyBusinessLogic {
public String doSomething();
}
class SampleBeanRegistrar : BeanRegistrarDsl({
registerBean<MyBusinessLogic>()
registerBean(::myRoutes)
})
open class MyApplication : SpringFunkApplication {
override fun dsl(): SpringDslContainer.() -> Unit = {
beans {
bean<MyBusinessLogic>()
}
webmvc {
enableWebMvc {
jetty()
}
routes {
router { service: MyBusinessLogic -> {
GET("/ping", service::doSomething)
}
}
}
}
}
}
class MyBusinessLogic {
public String doSomething();
}