Skip to content

i get an error when creating a graalvm native image #4294

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

Closed
joshlong opened this issue Feb 11, 2023 · 2 comments
Closed

i get an error when creating a graalvm native image #4294

joshlong opened this issue Feb 11, 2023 · 2 comments
Labels
status: duplicate Issues that are duplicates of other issues type: bug

Comments

@joshlong
Copy link
Member

i get an error about a proxy being created for JobOperator when creating a GraalVM native image with the following java code and build file:

build file

Here's the build file:

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.0.2'
	id 'io.spring.dependency-management' version '1.1.0'
	id 'org.graalvm.buildtools.native' version '0.9.18'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-batch'
	implementation 'org.springframework.boot:spring-boot-starter-jdbc'
	implementation 'org.postgresql:postgresql'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.batch:spring-batch-test'
}

tasks.named('test') {
	useJUnitPlatform()
}

Java code

package com.example.batch;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.transaction.PlatformTransactionManager;

import java.util.UUID;

@SpringBootApplication
public class BatchApplication {

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

    @Bean
    ApplicationRunner runner(JobLauncher jobLauncher, Job job) {
        return args -> {
            var jobParameters = new JobParametersBuilder()
                    .addString("uuid", UUID.randomUUID().toString())
                    .toJobParameters();
            var run = jobLauncher.run(job, jobParameters);
            var instanceId = run.getJobInstance().getInstanceId();
            System.out.println("instanceId: " + instanceId);
        };
    }

    @Bean
    @StepScope
    Tasklet tasklet(@Value("#{jobParameters['uuid']}") String uuid) {
        return (contribution, context) -> {
            System.out.println("hello, world! the UUID is " + uuid);
            return RepeatStatus.FINISHED;
        };
    }

    @Bean
    Job job(JobRepository jobRepository, Step step) {
        return new JobBuilder("job", jobRepository)
                .start(step) //
                .build();
    }

    @Bean
    Step step1(JobRepository jobRepository, Tasklet tasklet, PlatformTransactionManager transactionManager) {
        return new StepBuilder("step1", jobRepository) //
                .tasklet(tasklet, transactionManager) //
                .build();
    }
}

It runs fine on the JRE. And obviously, if I register the hint, it works fine too:

 @ImportRuntimeHints(Hints.class) 

and

    static class Hints implements RuntimeHintsRegistrar {

        @Override
        public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
            hints.proxies().registerJdkProxy(
                    org.springframework.batch.core.launch.JobOperator.class,
                    org.springframework.aop.SpringProxy.class, org.springframework.aop.framework.Advised.class, org.springframework.core.DecoratingProxy.class
            );
        }
    }
@joshlong joshlong added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Feb 11, 2023
@hpoettker
Copy link
Contributor

This is a duplicate of #4248.

A heads-up in case you want to run native tests with @SpringBatchTest: #4286

@fmbenhassine
Copy link
Contributor

Thank you for reporting this, Josh!

As mentioned by @hpoettker, this has been already reported in #4248. The fix will be included in the upcoming 5.0.1 (and is already available in the snapshots).

@hpoettker Thank you for the follow up!

@fmbenhassine fmbenhassine closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2023
@fmbenhassine fmbenhassine added status: duplicate Issues that are duplicates of other issues and removed status: waiting-for-triage Issues that we did not analyse yet labels Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate Issues that are duplicates of other issues type: bug
Projects
None yet
Development

No branches or pull requests

3 participants