Giter Club home page Giter Club logo

Comments (3)

scottfrederick avatar scottfrederick commented on May 3, 2024

Thanks for getting in touch. Unfortunately there's not enough information here for us to understand exactly what you are doing. If you would like us to spend some time investigating, please provide a complete minimal sample that reproduces the problem. The reproducer should have the fewest dependencies possible, ideally without any Spring Cloud dependencies. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.

from spring-boot.

danparisi avatar danparisi commented on May 3, 2024

Dear @scottfrederick,
Thanks for your quick reply.

I managed to create a very small example reproducing the issue:
https://github.com/danparisi/spring-boot-native-environment-post-processor-issue

Instructions about how to run it are in the README, please let me know if anything is missing.

Thanks for the support

from spring-boot.

wilkinsona avatar wilkinsona commented on May 3, 2024

Your environment post-processed relies on reflection through its use of SnakeYAML and you haven't provided any reachability metadata to convey that information to GraalVM. You can see the failure by wrapping the body of your postProcessEnvironment in a try-catch block:

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        try {
            …
        }
        catch (Exception ex) {
            ex.printStackTrace(System.out);
        }
    }

Running the native image will then show the failure:

Can't construct a java object for tag:yaml.org,2002:com.myservice.mytechlibrary.processor.SpringConfigImportEnvironmentPostProcessor$SpringProperties; exception=java.lang.NoSuchMethodException: com.myservice.mytechlibrary.processor.SpringConfigImportEnvironmentPostProcessor$SpringProperties.<init>()
 in 'reader', line 1, column 1:
    spring:
    ^

	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:326)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:264)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:247)
	at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:201)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:185)
	at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:493)
	at org.yaml.snakeyaml.Yaml.load(Yaml.java:434)
	at com.myservice.mytechlibrary.processor.SpringConfigImportEnvironmentPostProcessor.getSpringPropertiesValue(SpringConfigImportEnvironmentPostProcessor.java:75)
	at com.myservice.mytechlibrary.processor.SpringConfigImportEnvironmentPostProcessor.postProcessEnvironment(SpringConfigImportEnvironmentPostProcessor.java:39)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:109)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:94)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
	at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
	at java.base@21/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:369)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:329)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
	at com.myservice.myservice.Application.main(Application.java:11)
	at java.base@21/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: org.yaml.snakeyaml.error.YAMLException: java.lang.NoSuchMethodException: com.myservice.mytechlibrary.processor.SpringConfigImportEnvironmentPostProcessor$SpringProperties.<init>()
	at org.yaml.snakeyaml.constructor.BaseConstructor.newInstance(BaseConstructor.java:382)
	at org.yaml.snakeyaml.constructor.BaseConstructor.newInstance(BaseConstructor.java:344)
	at org.yaml.snakeyaml.constructor.BaseConstructor.newInstance(BaseConstructor.java:340)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:164)
	at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:320)
	... 27 more
Caused by: java.lang.NoSuchMethodException: com.myservice.mytechlibrary.processor.SpringConfigImportEnvironmentPostProcessor$SpringProperties.<init>()
	at java.base@21/java.lang.Class.checkMethod(DynamicHub.java:1065)
	at java.base@21/java.lang.Class.getConstructor0(DynamicHub.java:1228)
	at java.base@21/java.lang.Class.getDeclaredConstructor(DynamicHub.java:2930)
	at org.yaml.snakeyaml.constructor.BaseConstructor.newInstance(BaseConstructor.java:376)
	... 31 more

You need to allow instances of SpringProperties to be created using reflection.

Unfortunately, errors like this that occur before logging has been set up need to be handled carefully, particularly in a native image. We may be able to improve the diagnostics here, but I'm not certain that we can.

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.