2

After migrating an app to Spring Boot 3.0.1 the configuration properties can no longer be loaded from the application.yml file.

It does not work on any class that previously was ok. The following configuration spec started failing with uninitialized property for region:

@ConfigurationProperties(prefix = "aws")
class AwsConfig {
    lateinit var region: Region
    var endpointUrl: URI? = null
}

I researched more modern ways of instantiating the properties and came up with the following:

package ...

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.bind.ConstructorBinding
import software.amazon.awssdk.regions.Region

@ConfigurationProperties(prefix = "aws")
data class AwsConfig @ConstructorBinding constructor(
    val region: Region
)

The entry point is annotated with the following:

@SpringBootApplication
@ConfigurationPropertiesScan
class Application

That causes NPEs now, leading me to believe this is rather a read-level issue. Has anyone encountered such a problem?

Roots of the stacktrace:

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@6fa1dc0c testClass = com.pkg.ApplicationContextTest, ...]
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:142)
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventConsumerLauncher' defined in file ... Error creating bean with name 'aws-com.pkg.AwsConfig': Could not bind properties to 'AwsConfig' : prefix=aws, ignoreInvalidFields=false, ignoreUnknownFields=true
    at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
...
Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'aws-com.pkg.AwsConfig': Could not bind properties to 'AwsConfig' : prefix=aws, ignoreInvalidFields=false, ignoreUnknownFields=true
    at app//org.springframework.boot.context.properties.ConstructorBound.from(ConstructorBound.java:46)
...
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'aws' to com.pkg.AwsConfig
    at app//org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:387)
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.pkg.AwsConfig]: Constructor threw exception
    at app//org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:223)
...
Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method com.pkg.AwsConfig.<init>, parameter region
    at com.pkg.AwsConfig.<init>(AwsConfig.kt)

The faulty application.yml file looks like this:

server:
  port: -1

spring:
  config:
    activate:
      on-profile: integration

app:
  #...

aws:
  region: ${AWS_REGION:eu-west-1}
bart-kosmala
  • 931
  • 1
  • 11
  • 20

2 Answers2

1

High chances you are affected by this issue, which is still open for spring-boot 3.0.1.

You either apply the workarounds discussed under this issue, or wait for solution which probably be rolled out in spring-boot 3.0.2.

Panagiotis Bougioukos
  • 15,955
  • 2
  • 30
  • 47
1

This was an enterprise project where we explicitly declared some dependencies inline so that we could mitigate CVEs through version patching.

It turned out that for some reason, removing io.netty & org.apache.tomcat.embed declarations (used in the implementation scope) resolved the above problem.

bart-kosmala
  • 931
  • 1
  • 11
  • 20