Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy method not found in Native image for ExecutorService bean type #8136

Closed
RomanCht opened this issue Jan 10, 2024 · 1 comment
Closed
Labels

Comments

@RomanCht
Copy link

Describe the issue
I have a Spring Boot 3 (version 3.2.1) app with nothing on the classpath except spring-boot-starter.

if I use following code:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    ExecutorService executorService() {
        return Executors.newFixedThreadPool(10);
    }
}

...and then compile as Native image:

mvn clean native:compile -Pnative

...and run:

./target/demo

...then I get the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'executorService': Invalid destruction signature
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:643) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[demo:6.1.2]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:960) ~[demo:6.1.2]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[demo:6.1.2]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) ~[demo:3.2.1]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:464) ~[demo:3.2.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[demo:3.2.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1358) ~[demo:3.2.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1347) ~[demo:3.2.1]
        at com.example.demo.DemoApplication.main(DemoApplication.java:15) ~[demo:na]
Caused by: org.springframework.beans.factory.support.BeanDefinitionValidationException: Could not find a destroy method named 'shutdown' on bean with name 'executorService'
        at org.springframework.beans.factory.support.DisposableBeanAdapter.<init>(DisposableBeanAdapter.java:134) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.registerDisposableBeanIfNecessary(AbstractBeanFactory.java:1868) ~[demo:6.1.2]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:639) ~[demo:6.1.2]

And if I'll switch bean type to a precise one: (ThreadPoolExecutor) instead of (ExecutorService), then it works:

    // This works
    @Bean
    ThreadPoolExecutor executorService() {
        return (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
    }

    // This doesn't work
    @Bean
    ExecutorService executorService() {
        return Executors.newFixedThreadPool(10);
    }

This issue is almost exactly the same like this one: #29545 except that now it only reproducing for ExecutorService.

Steps to reproduce the issue
Please see reproducible Demo app: spring-native-executor-demo.zip

Describe GraalVM and your environment:

  • GraalVM version: 17.0.9-graal
  • JDK major version: 17
  • OS: macOS Sonoma 14.1.1 (23B81)
  • Architecture: ARM64
@RomanCht RomanCht added the bug label Jan 10, 2024
@RomanCht
Copy link
Author

Sorry, wrong Github Project. Closing this issue. Here's the correct one: spring-projects/spring-framework#32006

@RomanCht RomanCht closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant