Skip to content

JdkClassesMustNotBeInjectables to strict #4

@lostiniceland

Description

@lostiniceland

Applying the spring-boot:Strict group gives a constraint violation when injecting jdk classes.

The constraint JdkClassesMustNotBeInjectables seems overly strict because injecting a java.time.Clock is a valuable solution to set a fixed time in tests.

I assume the rule is valid only when there is no custom bean configuration available for the jdk type in use.
For instance, this is our clock-bean-configuration

@Configuration
class ClockConfiguration {

    @Bean
    fun clock(): Clock {
        return Clock.systemDefaultZone()
    }

    @Bean
    // needed for Hibernate Validators
    fun clockProvider(): ClockProvider {
        // ClockProvider only has one Method -> SAM-Type (Single-Abstract-Method)
        return ClockProvider { clock() }
    }
}

According this old post, it is not possible to exclude single rules. Is this still the case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions