Comments (3)
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.
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.
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)
- Bump gradle/actions from 3.3.0 to 3.3.1
- Bump gradle/actions from 3.3.0 to 3.3.1
- Consider delaying Jackson 2.17.0 upgrade in Spring Boot 3.3.0 HOT 2
- <springProperty> does not work in <include> after Logback upgrade HOT 5
- PulsarPropertiesMapper.getAuthenticationParamsJson HOT 6
- Spring-Boot 3.2 introduces permission issues in container images HOT 1
- Spring boot 3.2.5 @Preauthorize gives forbidden HOT 1
- Native image build fails with Maven and Java 21 HOT 3
- Remove unnecessary nesting of calls to String.format
- Remove unnecessary nesting of calls to String.format
- SpringBootMockMvcBuilderCustomizer can crash cryptically while collecting data that it would have discarded anyway
- CookieSameSiteSupplier influences session cookie
- Migrating from SpringBoot 2.7.1 to 3.2.3 but Lombok @SuperBuilder is not working getting error: cannot find symbol HOT 1
- Clarify docs around spring.jpa.generate-ddl
- FileSystemProviders from jar-files are not found when running as executable jar generated via spring-boot-maven-plugin HOT 1
- Upgrade CI to Docker 26.1.0
- Upgrade CI to Docker 26.1.0
- Upgrade CI to Docker 26.1.0
- Containers not shut down between tests when using .withReuse(true) but env. does not support reuse (e.g. CI builds)
- Containers not shut down between tests when using .withReuse(true) but env. does not support reuse (e.g. CI builds)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.