Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

293
Visualizações
Flux Not showing in Thymeleaf if Spring Web Security is enabled

I'm trying to show a Flux of Strings from my Controller to a view in Thymeleaf but i'm getting just a ReactiveDataDriverContextVariable on the view

I'm using Spring boot 2

This is my controller code

@GetMapping("/demo")
fun demo(model: Model): String{
    val data = Flux.just("ONE", "TWO", "THREE", "FOUR")
    model.addAttribute("data", ReactiveDataDriverContextVariable(data,1))
    return "demo"
}

And this is my Thymeleaf template code

    <table class="table table-striped table-responsive">
        <tr th:each="c: ${data}">
            <td th:text="${c}">...</td>
        </tr>
    </table>

As far as i know ReactiveDataDriverContextVariable should put thymeleaf in a data-driven mode and show a list of the four Strings but i'm just getting this output:

org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable@30ece48

I'm sure there is something i'm missing Thank you in advance

EDIT 1

Seems to be a problem with Spring Security

I have this configuration enabled

@EnableWebSecurity
class SecurityConfig : WebSecurityConfigurerAdapter() {

    override fun configure(http: HttpSecurity) {
        http.authorizeRequests()
                .antMatchers("/demo")
                .permitAll()
    }

}

When i delete Spring Security configuration and dependency everything works just fine but i would like to secure the webapp

any ideas?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I had the same issue. My problem was that for other reasons I also had org.springframework.boot:spring-boot-starter-web as dependency, so thymeleaf did not enable its reactive mode.

After I removed it, it started to work, but it only accepted a Flux and I couldn't render a single value. Looks like they only support iteration (th:each) on a stream, but I couldn't find a proper documentation only hello world examples.

My use case was different. I just did not want to block until I have my singe data object, so I came up with a workaround that also works with -web. I deferred the view name until I receive the data from the server. This way I don't need to block before I return the view name to start the rendering. (This method only works If you don't want to stream a long list) For -webflux you don't need this workaround, just simply put your Monos and Fluxes into the model. Webflux will automatically wait for them before calling thymeleaf.

WebMVC workaround:

@GetMapping("/article/{articleId}/{friendlyUrl}") fun article(@PathVariable articleId: String, @PathVariable friendlyUrl: String, model: Model): Mono<String> { return gwDispatcher.dispatch(GetArticleGwCommand(articleId)).map { it.article }.map { model.addAttribute("article", it) model.addAttribute("name", "Josh Smith"); "article" } }

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda