You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when using ConfigurationProperties, compilation will succeed but an error is thrown at runtime. this can be reproduced by applying the below patch against the commandLinerunner sample:
diff --git a/samples/commandlinerunner/clr b/samples/commandlinerunner/clr
new file mode 100755
index 0000000..8c1b419
Binary files /dev/null and b/samples/commandlinerunner/clr differ
diff --git a/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/CommandlinerunnerApplication.java b/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/CommandlinerunnerApplication.java
index 70f687e..fb342e1 100644
--- a/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/CommandlinerunnerApplication.java
+++ b/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/CommandlinerunnerApplication.java
@@ -3,9 +3,11 @@ package com.example.commandlinerunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@SpringBootApplication(proxyBeanMethods=false)
+@EnableConfigurationProperties(PropTest.class)
public class CommandlinerunnerApplication {
// private static final Logger LOGGER;
diff --git a/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/PropTest.java b/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/PropTest.java
new file mode 100644
index 0000000..f0a3e2f
--- /dev/null
+++ b/samples/commandlinerunner/src/main/java/com/example/commandlinerunner/PropTest.java
@@ -0,0 +1,16 @@
+package com.example.commandlinerunner;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties("com.example")
+public class PropTest {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
running the application yields the following:
SEVERE: Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example-com.example.commandlinerunner.PropTest': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.commandlinerunner.PropTest]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.commandlinerunner.PropTest.<init>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1307)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1201)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:404)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1275)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1263)
at com.example.commandlinerunner.CommandlinerunnerApplication.main(CommandlinerunnerApplication.java:29)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.example.commandlinerunner.PropTest]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.example.commandlinerunner.PropTest.<init>
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1299)
... 16 more
Caused by: java.lang.NoSuchMethodException: com.example.commandlinerunner.PropTest.<init>
at java.lang.Class.getConstructor0(DynamicHub.java:3082)
at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2178)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
... 17 more
The text was updated successfully, but these errors were encountered:
We might eventually add a feature for user-provided configuration properties. Until then the workaround is easy: just add the com.example.commandlinerunner.PropTest to your META-INF/native-image/reflect-config.json.
using GraalVM CE 19.0.2
when using
ConfigurationProperties
, compilation will succeed but an error is thrown at runtime. this can be reproduced by applying the below patch against thecommandLinerunner
sample:running the application yields the following:
The text was updated successfully, but these errors were encountered: