SpringBoot: @PreDestroy只有bean为singleton时有效

package cn.edu.tju.controller;

import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
//@Scope("prototype")
public class TestController {

    @PreDestroy
    public void myPreDestroy(){
        System.out.println(" my pre destroy......");
    }

    @PostConstruct
    public void myPostConstruct(){
        System.out.println("my post construct......");
    }

    @RequestMapping("/getInfo")
    public String getInfo(){
        System.out.println(this);
        return "hello, world!";
    }
}

你可能感兴趣的:(SpringBoot,spring,boot,单例模式,java)