0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CDIされたBeanについて、@PostConstructor, @PreDestroyの呼ばれるタイミングを確認

0
Posted at

CDIのBeanについて@PostConstructor, @PreDestroyの呼ばれる順番を
確認する。
コンソールに吐き出したログを確認。

Bb.java
@Named
@RequestScoped
//@SessionScoped
public class Bb implements Serializable{
    private String text;
    static {
        System.out.println(" bb static initializerがコールされた");
    }
    {
        System.out.println("bb initializerがコールされた");
    }
    
    public Bb() {
        System.out.println("bb constructがコールされた");
    }
    @PostConstruct
    public void pconstruc1() {
        System.out.println("bb postconstructがコールされた");        
    }
    @PreDestroy
    public void pdestroy1() {
        System.out.println("bb predestroyがコールされた");        
    }
    @Override
    protected void finalize() throws Throwable{
        System.out.println("bb finalizeがコールされた");        
        super.finalize();
    }

実行結果

  bb initializerがコールされた|#]
  bb constructがコールされた|#]
  bb postconstructがコールされた|#]
  bb predestroyがコールされた|#]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?