Spring Boot created @Bean with interface the @PostConstruct not called with native image

166 Views Asked by At

Spring Boot 3.1.3
graalvm-jdk-17.0.8+9.1

When creating bean manually from configuration and return interface the bean @PostConstruct is NOT called.
The workaround I found is to return implementing class and not interface.
Without native image same works without workaround. Not sure if expected or a BUG ?

public interface MyBean {
}

public class MyBeanImpl implements MyBean {

    @PostConstruct
    public void init() {
    }
}

@Configuration
public class MyConfig {

    // when returning MyBeanImpl it works fine
    @Bean 
    public MyBean myBean() { 
        return new MyBeanImpl();
    }
}
0

There are 0 best solutions below