Can I use SpringMvc and webflux together?

As explained in the Spring Boot reference documentation, Spring Boot will auto-configure a Spring MVC application if both MVC and WebFlux are available. There are several reasons for this: Spring MVC can’t run on Netty both infrastructure will compete for the same job (for example, serving static resources, the mappings, etc) mixing both runtime models … Read more

Spring Boot 2.0 disable default security

According to the new updates in Spring 2.0, if Spring Security is on the classpath, Spring Boot will add @EnableWebSecurity.So adding entries to the application.properties ain’t gonna work (i.e it is no longer customizable that way). For more information visit the official website Security changes in Spring Boot 2.0 Albeit not sure about your requirement … Read more

Enable CORS in Spring 5 Webflux?

I had success with this custom filter: import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.web.cors.reactive.CorsUtils; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; @Configuration public class CorsConfiguration { private static final String ALLOWED_HEADERS = “x-requested-with, authorization, Content-Type, Authorization, credential, X-XSRF-TOKEN”; private static final String ALLOWED_METHODS = “GET, … Read more

Spring 5 WebClient using ssl

Looks like Spring 5.1.1 (Spring boot 2.1.0) removed HttpClientOptions from ReactorClientHttpConnector, so you can not configure options while creating instance of ReactorClientHttpConnector One option that works now is: val sslContext = SslContextBuilder .forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE) .build() val httpClient = HttpClient.create().secure { t -> t.sslContext(sslContext) } val webClient = WebClient.builder().clientConnector(ReactorClientHttpConnector(httpClient)).build() Basically while creating the HttpClient, we are … Read more

block()/blockFirst()/blockLast() are blocking error when calling bodyToMono AFTER exchange()

First, a few things that will help you understand the code snippet solving this use case. You should never call a blocking method within a method that returns a reactive type; you will block one of the few threads of your application and it is very bad for the application Anyway as of Reactor 3.2, … Read more

How to log request and response bodies in Spring WebFlux

This is more or less similar to the situation in Spring MVC. In Spring MVC, you can use a AbstractRequestLoggingFilter filter and ContentCachingRequestWrapper and/or ContentCachingResponseWrapper. Many tradeoffs here: if you’d like to access servlet request attributes, you need to actually read and parse the request body logging the request body means buffering the request body, … Read more

how to log Spring 5 WebClient call

You can easily do it using ExchangeFilterFunction Just add the custom logRequest filter when you create your WebClient using WebClient.Builder. Here is the example of such filter and how to add it to the WebClient. @Slf4j @Component public class MyClient { private final WebClient webClient; // Create WebClient instance using builder. // If you use … Read more

Fire and forget with reactor

1, If your fire-and-forget is already async returning Mono/Flux public Flux<Data> search(SearchRequest request) { return searchService.search(request) .collectList() .doOnNext(data -> doThisAsync(data).subscribe()) // add error logging here or inside doThisAsync .flatMapMany(Flux::fromIterable); } public Mono<Void> doThisAsync(List<Data> data) { //do some async/non-blocking processing here like calling WebClient } 2, If your fire-and-forget does blocking I/O public Flux<Data> search(SearchRequest request) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)