How to use OpenAPI “oneOf” property with openapi-generator-maven-plugin when generating Spring code

Currently, openapi-generator doesn’t support oneOf. This is a capability that had been newly introduced with OpenAPI v3 (FYI, only v2 and below are called “Swagger”, it has then been renamed to OpenAPI). There are various generators (Java, Spring, lots of other languages). I have seen that contributions have been made during this year to enable … Read more

How to cope with x-forwarded-headers in Spring Boot 2.2.0? (Spring Web MVC behind reverse proxy)

With Spring Boot <= 2.1.x you had to provide a ForwardedHeaderFilter-Bean. Since Spring Boot 2.2.0 you don’t have to do this anymore. Just add server.forward-headers-strategy=NATIVE or server.forward-headers-strategy=FRAMEWORK to your application.properties-file. NATIVE means that the servlet container (e.g. undertow, tomcat) is resolving the x-forwarded-*-headers which is fine in most cases. If you rely on X-Forwarded-Prefix than … Read more

How to post request with spring boot web-client for Form data for content type application/x-www-form-urlencoded

We can use BodyInserters.fromFormData for this purpose webClient client = WebClient.builder() .baseUrl(“SOME-BASE-URL”) .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) .build(); return client.post() .uri(“SOME-URI) .body(BodyInserters.fromFormData(“username”, “SOME-USERNAME”) .with(“password”, “SONE-PASSWORD”)) .retrieve() .bodyToFlux(SomeClass.class) .onErrorMap(e -> new MyException(“messahe”,e)) .blockLast();

Spring Boot. @DataJpaTest H2 embedded database create schema

I had the same issue, I managed to resolve by creating schema.sql (in resources folder) with the content CREATE SCHEMA IF NOT EXISTS <yourschema> Documentation can be found here but imho the lack of real examples make it very complex. Warning: this script is also executed within the normal (not test) environment. Not mandatory, but … Read more

Log4j.properties in Spring boot

If you want spring boot to use log4j instead of its own default logging (logback) then you have to exclude default logging and include the log4j dependency for spring boot in your pom.xml: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> </dependency> that way is going to look for your … Read more

How to configure logback in spring-boot for ANSI color feature?

This is described in the coloring section of the Logback documentation: Grouping by parentheses as explained above allows coloring of sub-patterns. As of version 1.0.5, PatternLayout recognizes “%black”, “%red”, “%green”,”%yellow”,”%blue”, “%magenta”,”%cyan”, “%white”, “%gray”, “%boldRed”,”%boldGreen”, “%boldYellow”, “%boldBlue”, “%boldMagenta”, “%boldCyan”, “%boldWhite” and “%highlight” as conversion words. These conversion words are intended to contain a sub-pattern. Any sub-pattern … Read more

Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup

I was able to solve this by downgrading Spring Boot: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.3.3.RELEASE</version> </dependency> Guess it’s just not compatible with 2.4.0 yet. Specifically I also had to ensure that I used 2.3.3.RELEASE and not anything more recent due to other issues I ran across.

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