Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

@Order doesnt work with native build #1694

Closed
thekalinga opened this issue Aug 19, 2022 · 2 comments
Closed

@Order doesnt work with native build #1694

thekalinga opened this issue Aug 19, 2022 · 2 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@thekalinga
Copy link

thekalinga commented Aug 19, 2022

When I create a native image of spring application that uses @Order, native executable doesnt respect @Order specified while the non-native image version respects it.

  interface Contract {
    void perform();
  }

  @Component
  @Order(1)
  static class FirstContract implements Contract {
    @Override
    public void perform() {
      System.out.println("First contract: Done");
    }
  }

  @Component
  @Order(555)
  static class SecondContract implements Contract {
    @Override
    public void perform() {
      System.out.println("Second contract: Done");
    }
  }

  @Component
  @Order(9999)
  static class LastContract implements Contract {
    @Override
    public void perform() {
      System.out.println("Last contract: Done");
    }
  }

  @Bean
  ApplicationRunner onInit(List<Contract> contracts) {
    return args -> contracts.forEach(Contract::perform);
  }

When I run native image ( ./gradlew nativeCompile) I get the following output (ordered based on classname)

First contract: Done
Last contract: Done
Second contract: Done

If I run the same program in regular JVM, I get the following output (correctly ordered based on @Order)

First contract: Done
Second contract: Done
Last contract: Done

Version info

  1. Java
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8)
OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)
  1. OS Ubuntu 20.04.4 LTS
  2. Graal VM 22.2.r17-grl
  3. Spring & Gradle versions can be found can be found at this minimum reproducible sample

PS: I havent tried with org.springframework.core.Ordered, javax.annotation.Priority, org.springframework.core.PriorityOrdered & other ways to specify order. Issue might exist even there too. Please check if the issue occurs even with that.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 19, 2022
@sdeleuze
Copy link
Contributor

@snicoll Same happen with Spring Boot 3 snapshots, should we ask creating an issue on Spring Framework 6 side?

@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 22, 2022
@snicoll snicoll self-assigned this Aug 22, 2022
@snicoll snicoll added this to the 0.12.2 milestone Aug 22, 2022
@thekalinga
Copy link
Author

Thanks for the fix. Does this fix address all of these aswell?

PS: I havent tried with org.springframework.core.Ordered, javax.annotation.Priority, org.springframework.core.PriorityOrdered & other ways to specify order. Issue might exist even there too. Please check if the issue occurs even with that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

4 participants