How to use #RegisterReflectionForBinding with nested types in Spring Boot 3? - spring

I'm currently using #RegisterReflectionForBinding({ A.class, B.class }) to tell GraalVM's native-image what classes I need to process with reflection.
But how do I use it for nested types?
Note: Using spring-native and Spring Boot 2.x, I could specify a nested type as a string using #TypeHint(typeNames = "C$NestedType").

Related

Scala + Spring boot #Profile annotation

I'm trying to use profiles in my Scala application which is using spring boot framework.
I only added this annotation to my class
#Profile("config.local")
class LocalConfig with Config
However the compiler says it expects an array of String, but trying to make it work with Array, Seq, etc it is saying it expect an String there.
This is the error sbt shows:
Error:(16, 10) type mismatch; found : String("config.local")
required: Array[String] #Profile("config.local")
How can I use spring boot #Profile with Scala classes
Thanks
#Profile(Array("config.local"))
will work for you, but it may cause errors in the IDE although it compiles successfully.

Passing a List of Enum to Spring REST using Get method #QueryParam

I am using Spring and I need to pass a list consisting of enum values using the GET METHOD. Is it possible to use #QueryParam for a List ? If yes, then how and how do we send it through the url.
I used #QueryParam List enumValues and sent data through the url as enumValues=value1&enumVales=value2.
But I get the following error:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface
Please help!
You are facing this issue because you are using JAX-RS annotation #QueryParam with spring. Spring is not compliant to JAX-RS framework, they are completely two different MVC frameworks. If you rather use Spring annotation #RequestParam, the configuration is simple and it will create list of Enum for you:
Your query parameters will look like this: enumValues=value1&enumVales=value2
Your spring RequestMapping will look like: #RequestParam(value="enumValues")List<EnumValues> enumValues

Yaml type-safe configuration in Spring using Kotlin Functional Style

I'm trying to follow the demo https://github.com/sdeleuze/spring-kotlin-functional to create a new Spring Boot application using the annotation-free new approach, released in Spring Boot 2. My problem is how to continue to use Yaml files to configure my application, without using annotations? I would guess it would be something inside the Beans configuration but I dont find any documentation on that subject. Thanx
The beans dsl has an env property that you can use to retrieve any environment property defined in yaml, properties files or command line parameters:
fun beans() = beans {
bean<SomeBeanThatNeedsConfig> {
SomeBeanThatNeedsConfig(env.getProperty("config.value"))
}
}

Jackson Custom Deserializer/Serializer with Spring MongoTemplates

I am having trouble accessing and writing data from/to mongoDB using spring mongoTemplate.
For starters I have a data-model that represents the object that I am trying to retrieve from mongo. I have it annotated with #JsonSerialize and #JsonDeserialize for specifying custom converters.
However when I invoke mongoTemplate.findById(), and try to get this object, I find that my custom deserializer is not invoked at all and I get HttpMessageNotWriteableException.
Is there any other configuration that must be put in place to let mongo know that it needs to use my custom Jackson deserializer?
You can use this for reference: https://gist.github.com/letalvoj/978e6c975398693fc6843c5fe648416d

Javers InstantiationError in spring environment

When trying to instantiate Javers using:
JaversBuilder.javers().build()
I keep getting the following runtime exception:
java.lang.InstantiationError: org.picocontainer.monitors.AbstractComponentMonitor
I am using javers-core 2.9.1 in a spring environment, however, I do not want to use any of the repository functionality, I just want to be use the object diff. In the getting started documentation it says you can simply use: Javers javers = JaversBuilder.javers().build(); and then compare to objects.
In a spring environment is there more that needs to be done? I am using JPA Entities and MappedSuperclasses (my object extends multiple levels of MappedSuperClasses of which the final one has a JPA #ID annotation.
Thanks,
Chris.

Resources