spring默认是单例的,在开发过程中也可以把spring通过注解配置成@Scope(value = "prototype"),可以保证 当有请求的时候 都创建一个spring对象

解决方案 »

  1.   

    也可以在struts的配置文件中指定:<constant name="struts.objectFactory" value="spring"/> 交给spring管理就一切OK了
      

  2.   

    BO tier and DAO tier you mentioned are basically designed to be singular instance.It's definitely correct.And yet, they are also designed to be stateless bean.That is to say,they often only own service methods without carrying any data.That means there is no sharing data between multiple threads unless you can guarantee not to access a sharing class which is stateful class in your BO or DAO.Therefore,it's impossible to produce thread-safe issue.
    However,in case you need to access a sharing class which is stateful class in your BO or DAO,it is proposed to design it to be thread-safe class by adding keyword sychronized or other newly APIs (since JDK 1.5 )to tackle thread-safe issues.
    Above all, just from my point of view.I hope it's beneficial and favorable to cure your concern.
      

  3.   


    那你的意思是说,如果是web网站,像上面我说的情况,spring IOC注入的就不能是单例?可是我的案例项目中,并没有这样做啊。所以我才觉得奇怪
      

  4.   

    bo 和dao类中不要有成员变量,也就不会有共享的数据,也就不会有线程安全问题