i am not able to get ISO formatted dates.
Setup:
Kotlin 1.7.10
Spring Boot 2.7.1
Jackson 2.13.3
with following jackson dependencies:
jackson-module-kotlin
jackson-databind
Application properties
spring:
jackson:
date-format: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
default-property-inclusion: non_null
serialization:
write-dates-as-timestamps: false
INDENT_OUTPUT: true
deserialization:
FAIL_ON_UNKNOWN_PROPERTIES: false
FAIL_ON_INVALID_SUBTYPE: false
I also tried moving this config to class level but no difference.
It only works when i use property annotations like:
#JsonProperty("startTimestamp")
#JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
var startTimestamp: LocalDateTime
But that's not an option.
Edit
I also tried:
Overriding the default configuration of ObjectMapper
Customizing the ObjectMapper using Jackson2ObjectMapperBuilderCustomizer
Related
we are currently having an issue with spring-cloud-sleuth and logback.
We are using sleuth to add trace information to our logback-logs which is working fine but when we hit the /actuator/refresh endpoint certain springProperty's that we define in the logback-spring.xml just disappear in all subsequent logs. These properties are defined in the gradle.properties file and injected into the application.yml on buid-time. We pinpointed the problem to be in the org.springframework.cloud:spring-cloud-starter-sleuth dependency. as soon as we remove it the refresh and logs work fine.
Here are some codesnippets that might help:
SpringProperty in logback-spring.xml:
<springProperty scope="context" name="version" source="spring.build.version"/>
application.yml definition of the variable:
spring:
build:
version: ${version}
Version definition in gradle.properties:
version=1.23
gradle sleuth dependency:
implementation("org.springframework.cloud:spring-cloud-starter-sleuth")
An example of a log message before refresh:
{
"level":"INFO",
"logger_name":"xx",
"message":"this is a message",
"thread_name":"boundedElastic-1",
"sequence":13,
"environment":"dev",
"version":"1.23",
"service":"my-service",
"traceId":"aa2d403b1d9a76a6",
"spanId":"aa2d403b1d9a76a6"
}
And after refresh:
{
"level":"INFO",
"logger_name":"xx",
"message":"this is another message",
"thread_name":"boundedElastic-1",
"sequence":2,
"environment":"development",
"traceId":"aa2d403b1d9a76a6",
"spanId":"aa2d403b1d9a76a6"
}
Thank you for your help!
I'm trying to test openapi codegenerator via gradle plugin. So, I have .yml file with documentation (ran it in https://editor.swagger.io/ , looks cool)
openapi: 3.0.2
info:
title: Testing docs
version: 1.0.0
tags:
- name: Registration
paths:
/registration:
post:
tags:
- Registration
summary: Register user
...
Here's part of my build.gradle
plugins {
id "org.openapi.generator" version "5.0.1"
}
def sDir= "$buildDir/generated"
openApiGenerate {
generatorName = "spring"
inputSpec = "$rootDir/src/main/resources/documentation/openapi.yml"
outputDir = "${sDir}"
apiPackage = "generated.api"
invokerPackage = "generated.invoker"
modelPackage = "generated.model"
configOptions = [
interfaceOnly: "true",
useTags: "true"
]
}
...
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-ui:1.5.2'
implementation 'io.springfox:springfox-swagger2:3.0.0'
implementation 'org.openapitools:jackson-databind-nullable:0.2.1'
}
I've got bunch of generated interfaces annotated with #Tag and #Api, implemented some of them, but on /swagger-ui.html I do not see tags. Like, I'm getting "not implemented" status, when I run not implemented requests, but I do not see right ui - it looks autogenerated, like when you don't use any of swagger annotations on methods. I can only think that I messed up with some dependencies, but can't really get a clue.
The ui you see is not generated from the documentation .yml file you use to generate your code.
Instead, the ui is generated from the generated code, which has it's own annotations that currently are springfox annotations, which are swagger2 annotations instead of openapi 3 annotations (although your original file is openapi 3).
Generated openapi 3 annotations support is coming soon, but in any case, in short, you should have to complete missing annotations and necessary beans yourself, but this way makes it very hard to match the resulting openapi definition to your original documentation file.
Luckily there's a better alternative:
Just add your yml file in src/main/resources/static and add this line to your application.properties file:
springdoc.swagger-ui.url=/<your_file>.yml
As stated here https://springdoc.org/#how-can-use-custom-jsonyml-file-instead-of-generated-one.
You already have springdoc-ui dependency so you don't need to add any more dependencies.
This will ignore your code annotations and generate the ui directly from your documentation .yml file
I am trying to run gradlew flywayMigrate, and the application chrashes when running a recurring migration with the error
Caused by: org.flywaydb.core.api.FlywayException: No value provided for placeholder expressions: ${dbLinkHost}, ${dbLinkPassword}, ${dbLinkSid}, ${dbLinkUser}. Check your configuration!
The variables are configured like this in application.yml:
flyway:
placeholders:
dbLinkHost: ...
dbLinkSid: ...
dbLinkUser: ...
dbLinkPassword: ...
And I try to access them like this in the sql file:
'${dbLinkHost}'
Does anyone know why the declarations in application.yml don`t seem to be accessible here?
As a result of Spring Boot Issue #9896 - Move Flyway configuration properties to spring.flyway and commit f9e3163, starting with v2.0.0.M4, Flyway configuration properties in your application properties start with spring.flyway. To configure Flyway placeholders, for example:
spring:
flyway:
placeholders:
dbLinkHost: ...
dbLinkSid: ...
dbLinkUser: ...
dbLinkPassword: ...
In Spring Boot versions before v2.0.0.M4 such as the recently-released v1.5.14.RELEASE, Flyway configuration properties start with flyway.
I use Spring 3.0 to annotate a scheduled task:
#Scheduled(fixedRateString = "${UPDATE_RATE}")
However, I want to store the properties in application.conf, not application.properties:
conf {
UPDATE_RATE = 60000
}
It looks like Spring cannot find UPDATE_RATE in the file application.conf, because it expects application.properties.
Is there any way to use *.conf instead of *.properties?
I would like externalize the configuration of my aplication, I use Spring Boot 1.3.0, and I kwnow that the class ConfigFileApplicationListener has a default value DEFAULT_SEARCH_LOCATIONS. How can I change the source of my configuration, before this class load the default properties source?
You can use #PropertySource annotation on your configuration class (which is annotated #SpringBootApplication or #Configuration).
Like this:
#SpringBootApplication
#PropertySource(value = { "classpath:other.properties", "file:./other-external.properties" }, ignoreResourceNotFound = true)
public class MyApplication {
It will search first other.properties in your classpath and then looks the external file other-external.properties right outside of your jar or war file. Latest files overwrites values of other files (if they exists)
See https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html for more details.