-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Maksim Kostromin opened SPR-17244 and commented
With java, to render template engine views i can use RouterFunction<?> in routes bean:
@SpringBootApplication
public class Application {
@Bean RouterFunction routes(final ApplicationHandlers handlers) {
return //...skipped
.andOther(route(GET("/").and(accept(TEXT_HTML)), handlers::index))
;
}
// main skipped..
so with that, I can use both, ServerResponse:
Mono<ServerResponse> index(final ServerRequest request) {
return ok().contentType(TEXT_HTML)
.render("index", singletonMap("message", "Hello, World!"))
;
}
and RenderingResponse:
Mono<RenderingResponse> index(final ServerRequest request) {
return create("index").modelAttribute("message", "Hello, World!")
.build()
;
}
but unfortunately I can't do similar with Kotlin DSL:
@SpringBootApplication
class App {
@Bean fun routes() = router {
resources("/**", ClassPathResource("/static"))
("/").nest {
GET("/") {
create("index")
.modelAttribute("message", "hey")
.build()
}
}
}
}
see screenshot-1.png in attachment:
!screenshot-1.png|thumbnail!
Only Mono<ServerResponse> handler like so:
ok().contentType(TEXT_HTML)
.render("index", mapOf("message" to "hey"))
will works correctly... RenderingResponse extends ServerResponse, but unfortunately Mono<RenderingResponse> doesn't extend Mono<ServerResponse>
at the moment I can force it only with unchecked cast
see screenshot-2.png from attachment:
!screenshot-2.png|thumbnail!
GET("/") {
val res = create("index")
.modelAttribute("message", "hey")
.build()
res as Mono<ServerResponse>
}
I think it's bug
here some described source code repo: https://github.com/daggerok/spring-boot-oauth2/blob/master/src/main/java/daggerok/App.kt#L32
—
Regards,
Maksim Kostromin
Affects: 5.1 RC2
Reference URL: spring-projects/spring-boot#14300
Attachments:
- screenshot-1.png (135.95 kB)
- screenshot-2.png (144.91 kB)
Referenced from: commits f8a0e3d