Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Exception when using spring.profiles.active #798

Closed
ivangfr opened this issue May 27, 2021 · 4 comments
Closed

Exception when using spring.profiles.active #798

ivangfr opened this issue May 27, 2021 · 4 comments
Assignees
Labels
type: compatibility Native image compatibility issue
Milestone

Comments

@ivangfr
Copy link

ivangfr commented May 27, 2021

Hi, I've updated my project to spring-boot 2.4.6 (spring native is 0.9.2) and I am having the exception below when setting SPRING_PROFILES_ACTIVE to a Docker native image

In order to solve it, I needed to add @TypeHint(types = {Set.class, LinkedHashSet.class}) to my Spring application class.

Thanks!

[main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.profiles.active' to java.util.Set<java.lang.String>
	at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:363)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:323)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:308)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:238)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:199)
	at org.springframework.boot.context.config.Profiles.getProfiles(Profiles.java:101)
	at org.springframework.boot.context.config.Profiles.getActivatedProfiles(Profiles.java:88)
	at org.springframework.boot.context.config.Profiles.<init>(Profiles.java:82)
	at org.springframework.boot.context.config.ConfigDataEnvironment.withProfiles(ConfigDataEnvironment.java:278)
	at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:234)
	at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
	at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
	at java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:375)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318)
	at com.mycompany.springbootjpamysql.SpringbootJpaMysqlApplication.main(SpringbootJpaMysqlApplication.java:10)
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList<?>] to type [java.util.LinkedHashSet<java.lang.String>] for value '[native]'; nested exception is java.lang.IllegalArgumentException: Could not instantiate Collection type: java.util.LinkedHashSet
	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192)
	at org.springframework.boot.context.properties.bind.BindConverter$CompositeConversionService.convert(BindConverter.java:170)
	at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:96)
	at org.springframework.boot.context.properties.bind.IndexedElementsBinder.convert(IndexedElementsBinder.java:142)
	at org.springframework.boot.context.properties.bind.IndexedElementsBinder.bindValue(IndexedElementsBinder.java:97)
	at org.springframework.boot.context.properties.bind.IndexedElementsBinder.bindIndexed(IndexedElementsBinder.java:83)
	at org.springframework.boot.context.properties.bind.IndexedElementsBinder.bindIndexed(IndexedElementsBinder.java:70)
	at org.springframework.boot.context.properties.bind.CollectionBinder.bindAggregate(CollectionBinder.java:49)
	at org.springframework.boot.context.properties.bind.AggregateBinder.bind(AggregateBinder.java:56)
	at org.springframework.boot.context.properties.bind.Binder.lambda$bindAggregate$3(Binder.java:414)
	at org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:571)
	at org.springframework.boot.context.properties.bind.Binder$Context.access$100(Binder.java:512)
	at org.springframework.boot.context.properties.bind.Binder.bindAggregate(Binder.java:414)
	at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:375)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:319)
	... 27 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not instantiate Collection type: java.util.LinkedHashSet
	at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:212)
	at org.springframework.core.convert.support.CollectionToCollectionConverter.convert(CollectionToCollectionConverter.java:81)
	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
	... 42 common frames omitted
Caused by: java.lang.NoSuchMethodException: java.util.LinkedHashSet.<init>()
	at java.lang.Class.getConstructor0(DynamicHub.java:3349)
	at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2553)
	at org.springframework.util.ReflectionUtils.accessibleConstructor(ReflectionUtils.java:185)
	at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:208)
	... 44 common frames omitted
10:01:03.526 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter -

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.profiles.active' to java.util.Set<java.lang.String>:

    Property: spring.profiles.active
    Value: native
    Origin: System Environment Property "SPRING_PROFILES_ACTIVE"
    Reason: failed to convert java.util.ArrayList<?> to java.util.LinkedHashSet<java.lang.String>

Action:

Update your application's configuration

How to reproduce

  • git clone https://github.com/ivangfr/graalvm-quarkus-micronaut-springboot.git
  • cd graalvm-quarkus-micronaut-springboot/jpa-mysql
  • docker-compose up -d
  • cd springboot-jpa-mysql;
  • in pom.xml, update the spring-boot version to 2.4.6;
  • ./mvnw clean
  • ./docker-build.sh native
  • run docker container
    docker run --rm --name springboot-jpa-mysql-native \
      -p 9091:8080 -e SPRING_PROFILES_ACTIVE=native -e MYSQL_HOST=mysql \
      --network jpa-mysql_default \
      ivanfranchin/springboot-jpa-mysql-native:1.0.0
    
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 27, 2021
@sdeleuze
Copy link
Contributor

I added recently LinkedHashSet to Spring Boot hints, could you please try with 0.10.0-SNAPSHOT and Spring Boot 2.5.0? I have not added Set hint so maybe I need to refine it, let see based on your feedback.

@sdeleuze sdeleuze self-assigned this May 27, 2021
@sdeleuze
Copy link
Contributor

See also related #764 issue.

@ivangfr
Copy link
Author

ivangfr commented May 27, 2021

I tried using spring-boot 2.5.0 and spring-native 0.10.0-SNAPSHOT. I am getting

Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer : org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer
	at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:479)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:461)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:454)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:285)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:265)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325)
	at com.mycompany.springbootjpamysql.SpringbootJpaMysqlApplication.main(SpringbootJpaMysqlApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer
	at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:60)
	at java.lang.Class.forName(DynamicHub.java:1260)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
	at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:472)
	... 7 more

Then, I set Set.class to @TypeHint and it worked.

@sdeleuze sdeleuze added type: compatibility Native image compatibility issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 28, 2021
@sdeleuze sdeleuze added this to the 0.10.0 milestone May 28, 2021
@sdeleuze
Copy link
Contributor

Ok I will add it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: compatibility Native image compatibility issue
Development

No branches or pull requests

3 participants