Comment From: pivotal-issuemaster

@biuabiu Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-issuemaster

@biuabiu Thank you for signing the Contributor License Agreement!

Comment From: quaff

Current behavior base on class hierarchy if I recall correctly, will it breaks compatibility potentially?

Comment From: biuabiu

Current behavior base on class hierarchy if I recall correctly, will it breaks compatibility potentially?

The compatible change here means that if there are multiple '@Postconstructs', they will be executed according to '@Order'

Comment From: quaff

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

    public static void main(String[] args) throws Exception {
        try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
            ctx.register(Service2.class);
            ctx.refresh();
        }
    }

    static class Service0 {

        @PostConstruct
        private void init() {
            System.out.println("init Service0");
        }

        @PreDestroy
        private void destroy() {
            System.out.println("destroy Service0");
        }

    }

    static class Service1 extends Service0 {

        @PostConstruct
        private void init() {
            System.out.println("init Service1");
        }

        @PreDestroy
        private void destroy() {
            System.out.println("destroy Service1");
        }

    }

    static class Service2 extends Service1 {
        @PostConstruct
        private void init() {
            System.out.println("init Service2");
        }

        @PreDestroy
        private void destroy() {
            System.out.println("destroy Service2");
        }
    }

}

should always print

init Service0
init Service1
init Service2
destroy Service2
destroy Service1
destroy Service0

Please make sure your changes will not break it.

Comment From: biuabiu

such a change will indeed destroy the feature; I have revised it, you can review it @quaff

Comment From: quaff

I think it's not recommended to annotate such annotation on multiple methods, this PR is questionable.

Comment From: quaff

```java import javax.annotation.PostConstruct; import javax.annotation.PreDestroy;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

public static void main(String[] args) throws Exception { try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) { ctx.register(Service2.class); ctx.refresh(); } }

static class Service0 {

  @PostConstruct
  private void init() {
      System.out.println("init Service0");
  }

  @PreDestroy
  private void destroy() {
      System.out.println("destroy Service0");
  }

}

static class Service1 extends Service0 {

  @PostConstruct
  private void init() {
      System.out.println("init Service1");
  }

  @PreDestroy
  private void destroy() {
      System.out.println("destroy Service1");
  }

}

static class Service2 extends Service1 { @PostConstruct private void init() { System.out.println("init Service2"); }

  @PreDestroy
  private void destroy() {
      System.out.println("destroy Service2");
  }

}

} ```

should always print

init Service0 init Service1 init Service2 destroy Service2 destroy Service1 destroy Service0

Please make sure your changes will not break it.

@jhoeller Does it covered by unit test? I'm happy to submit PR if not.

Comment From: biuabiu

I think it's not recommended to annotate such annotation on multiple methods, this PR is questionable.

If there are more than one @PostConstruct or @PreDestroy in a class, I think it is necessary to guarantee the order. In addition, @Order also supports marking methods. What do you think?

Comment From: quaff

I think it's not recommended to annotate such annotation on multiple methods, this PR is questionable.

If there are more than one @PostConstruct or @PreDestroy in a class, I think it is necessary to guarantee the order. In addition, @order also supports marking methods. What do you think?

Why not merge them as one?

Comment From: biuabiu

I think it's not recommended to annotate such annotation on multiple methods, this PR is questionable.

If there are more than one @PostConstruct or @PreDestroy in a class, I think it is necessary to guarantee the order. In addition, @order also supports marking methods. What do you think?

Why not merge them as one?

Of course, what we are discussing now is whether to ensure the execution order when there is more than one

Comment From: quaff

I think it's not recommended to annotate such annotation on multiple methods, this PR is questionable.

If there are more than one @PostConstruct or @PreDestroy in a class, I think it is necessary to guarantee the order. In addition, @order also supports marking methods. What do you think?

Why not merge them as one?

Of course, what we are discussing now is whether to ensure the execution order when there is more than one

You are encourage not recommend usage, this will most likely be rejected by the spring team.

Comment From: biuabiu

I think it's not recommended to annotate such annotation on multiple methods, this PR is questionable.

If there are more than one @PostConstruct or @PreDestroy in a class, I think it is necessary to guarantee the order. In addition, @order also supports marking methods. What do you think?

Why not merge them as one?

Of course, what we are discussing now is whether to ensure the execution order when there is more than one

You are encourage not recommend usage, this will most likely be rejected by the spring team.

OK, thank you for reminding me. I hope they can accept it

Comment From: snicoll

Thanks for the PR but I agree with @quaff here.