Closed tushar256 closed 2 years ago
You should be able to fix that by adding proxy hints like @JdkProxyHint(types= { BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class })
. See related documentation in https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-hints. Spring Boot 3 native support should be able to infer such hint automatically.
Hello I am still getting the same error message after adding this
@JdkProxyHint(types= { BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class, ApplicationContextAware.class, EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class})
on Main Class ( annotated with @SpringBootApplication )
Complete Main Class:
`@JdkProxyHint(types= { BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class, ApplicationContextAware.class, EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class}) @NativeHint( types = { @TypeHint(types = {BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class, ApplicationContextAware.class, EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class}, access = {TypeAccess.PUBLIC_CONSTRUCTORS, PUBLIC_METHODS}), @TypeHint(types = {ConsoleAppender.class, SizeAndTimeBasedRollingPolicy.class, PatternLayout.class, RollingFileAppender.class, PatternLayoutEncoder.class}, access = {TypeAccess.PUBLIC_CONSTRUCTORS, PUBLIC_METHODS}) }) @AotProxyHints( { @AotProxyHint(interfaces ={BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class, ApplicationContextAware.class, EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class}), @AotProxyHint(targetClass = DefaultController.class, proxyFeatures = ProxyBits.IS_STATIC), @AotProxyHint(targetClass= KafkaReceiver.class, proxyFeatures = ProxyBits.IS_STATIC), @AotProxyHint(targetClass= KafkaSender.class, proxyFeatures = ProxyBits.IS_STATIC) } )
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) public class MicroserviceApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserviceApplication.class, args);
}
} `
Please find my sample code here: https://github.com/tushar256/hello-world
I tried your repro from https://github.com/tushar256/hello-world and it works with:
@NativeHint(
types = {
@TypeHint(types = {BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class, ApplicationContextAware.class, EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class},
access = {TypeAccess.PUBLIC_CONSTRUCTORS, PUBLIC_METHODS}),
@TypeHint(types = {ConsoleAppender.class, SizeAndTimeBasedRollingPolicy.class, PatternLayout.class, RollingFileAppender.class, PatternLayoutEncoder.class},
access = {TypeAccess.PUBLIC_CONSTRUCTORS, PUBLIC_METHODS})
}, jdkProxies = {
@JdkProxyHint(types= { BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class }),
@JdkProxyHint(types= { ApplicationContextAware.class, EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class }),
@JdkProxyHint(types= { java.util.List.class, java.util.RandomAccess.class, java.lang.Cloneable.class, java.io.Serializable.class, java.util.Collection.class })
})
@AotProxyHints( { @AotProxyHint(interfaces ={BeanPostProcessor.class, BeanFactoryAware.class, BeanClassLoaderAware.class, ApplicationContextAware.class,
EnvironmentCapable.class, EnvironmentAware.class, Servlet.class, ServletConfig.class, Serializable.class}),
@AotProxyHint(targetClass = DefaultController.class, proxyFeatures = ProxyBits.IS_STATIC),
@AotProxyHint(targetClass= KafkaReceiver.class, proxyFeatures = ProxyBits.IS_STATIC),
@AotProxyHint(targetClass= KafkaSender.class, proxyFeatures = ProxyBits.IS_STATIC) } )
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
after removing -H:DynamicProxyConfigurationFiles=/mnt/c/git/hello-world/target/classes/META-INF/native-image/proxy-config.json
whihc is useless since discovered automatically.
Thank you @sdeleuze it worked!!
Hello,
I am facing the following error when running spring boot native application:
Compiles successfully
mvn -Pnative -DskipTests -Dactive.profile=UAT clean package
Error while running
target/hello-world
My environment is: GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06) Open JDK 17.0.4 2022-07-19 Spring Boot: 2.7.1 spring-aot-maven-plugin: 0.12.1
After compiling ( mvn -Pnative -DskipTests -Dactive.profile=UAT clean package ) when I run my program, I get the above error.
Please find my minimal code sample here : https://github.com/tushar256/hello-world
Thanks