Spring

作者: 紫雨杰 | 来源:发表于2018-06-11 11:20 被阅读0次

一、Spring容器是单例的

 1、 Spring默认是单例的,可以通过scope属性更改为多例。

 2、因为是单例的,所以多线程访问下,可能会出现线程安全问题

二、解决方案:

1、在Controller中使用ThreadLocal变量

2、在spring配置文件Controller中声明 scope="prototype",每次都创建新的controller

   所以在使用spring开发web 时要注意,默认Controller、Dao、Service都是单例的。

相关文章

网友评论

    本文标题:Spring

    本文链接:https://www.haomeiwen.com/subject/biillftx.html