https://kotlinlang.org logo
#spring
Title
# spring
m

mp

07/13/2022, 12:57 PM
hi there did anyone update SB recently? (I`m moving from 2.5 to 2.7) Receiving
No default constructor found; nested exception is java.lang.NoSuchMethodException
on configuration class loading(with sb 2.6 and 2.7) that have been properly loaded(with SB 2.5) with constructor injection have I missed some important about bean configuration process updates?
m

Mikhail

07/13/2022, 1:38 PM
Do you have appropriate plugins enabled?
I'm using SB 2.7.1, works pretty fine for me.
m

mp

07/13/2022, 1:43 PM
spring jpa yes but still @configuration doesn’t affected by jpa(no args) plugin for 2.5 and 2.6\2.7 either and constructor binding works fine thats whats confuse me
m

Mikhail

07/13/2022, 1:44 PM
can you send here your
plugins {}
and the affected
@Configuration
class?
m

mp

07/13/2022, 1:50 PM
default
Copy code
apply plugin: "kotlin-jpa"
apply plugin: "kotlin-spring"
out contains this And its identical for both 2.5 and 2.6\2.7
m

Mikhail

07/13/2022, 1:53 PM
have you tried to use
plugins {}
block instead?
m

mp

07/13/2022, 1:56 PM
I assume that plugins works as documented • jpa - `The plugin specifies
@Entity
,
@Embeddable
, and
@MappedSuperclass
no-arg annotations automatically` • spring - makes open
@Component @Async @Transactional @Cacheable @SpringBootTest
thats why I haven’t try any plugins manipulations and can’t understand what has been broken in my case
m

Mikhail

07/13/2022, 1:59 PM
It looks like the plugins aren't applying somehow and this is why we should adjust your build script first
does the problem still appear on Kotlin 1.7.10 + SB plugin 2.7.1?
m

mp

07/13/2022, 2:17 PM
at the moments its 1.6.21 + 2.7.1
t

Thomas

07/13/2022, 2:28 PM
Copy code
@Configuration
class TodoService(
    private val todoRepository: TodoRepository,
    private val todoListRepository: TodoListRepository
) {
That`s your code?
m

mp

07/13/2022, 2:29 PM
that one already debbuged YmlFactory - it wokrs properly
t

Thomas

07/13/2022, 2:31 PM
are there multiple classes in one file?
m

mp

07/13/2022, 2:32 PM
yep
Copy code
@ConstructorBinding
@ConfigurationProperties("smart-server")
data class SmartServerProperties(
blablablah
) {
and another bean class
Copy code
class OneLineSmartServerLogger: Logger {
    private val lines = mutableListOf<String>()
    private val logger = Logger.DEFAULT

    override fun log(message: String) {
        lines.add(message)

        if (message.startsWith("BODY END")) {
            logger.log(lines.joinToString(separator = "\n"))
            lines.clear()
        }
    }
}
for ktor
t

Thomas

07/13/2022, 2:34 PM
m

mp

07/13/2022, 2:35 PM
was there - will try again
will recheck again - cos still regarding spring and kotlin documentation - it should work without default arg and its 🤯
t

Thomas

07/13/2022, 2:37 PM
yes it looks strange
it already was working even 😄
m

mp

07/13/2022, 2:38 PM
YES! thats why I came here)))
looks like it was mi migrations mistake I’ve rewrite it clearly step by step, separatly • kotlin bump • spring bump • etc and now it looks good
one more updt its not im trying to create in configuration KtorClient bean and setup it with properties data class created with constructor binding and it fails with no zero arg constructor last update THE last update 😂 it works properly if bean creation use all properties as args
Copy code
@Bean
    fun ktorClient(
        smartServerProperties: SmartServerProperties,
        @Value("\${http.connection-timeout}") httpConnectTimeout: Long,
        @Value("\${http.read-timeout}") httpReadTimeout: Long
    ) =
so it was my fail to try inject
Copy code
@ConstructorBinding
@ConfigurationProperties("smart-server")
data class SmartServerProperties(
to Configuration and missunderstanding of initialisation flow Tnx for your replies!
4 Views