spring注解设置单例和原型模式
spring默认是单例模式
import java.util.HashSet;
import java.util.Set;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value = "/spring")
@Scope("prototype")
public class SpringDemo {
private static Set<Object> set = new HashSet<>();
@RequestMapping(value="test")
public void test(){
set.add(this);
System.out.println(set.size());
}
}