当我在服务器上运行bean的方法的第一个小问题(比方法A)时,一切似乎都没问题,但是当第二次运行这个carrierRESTWS bean的任何请求时(假设方法B),使用的dao是相同的carrierDAO实例。 我怎样才能避免出现这个问题并且每次调用这个carrierRESTWS bean时注入使用dao的新实例?
xml文件中的Bean配置:
<bean id="carrierRESTWS" class="ar.com.anovo.controllers.rest.CarrierRESTWS"> <property name="carrierDAO" ref="carrierDAO"/> </bean> <bean id="carrierDAO" class="ar.com.anovo.dao.CarrierDAO"></bean>When i run the first petittion of a bean's method (let's say method A) on the server everything seems ok, but when running for the second time any petition on this carrierRESTWS bean (let's say method B), the dao being used is the same carrierDAO instance. How can i avoid having this problem and making the injection use a new instance of the dao each time this carrierRESTWS bean is being called?
Beans configuration inside xml file:
<bean id="carrierRESTWS" class="ar.com.anovo.controllers.rest.CarrierRESTWS"> <property name="carrierDAO" ref="carrierDAO"/> </bean> <bean id="carrierDAO" class="ar.com.anovo.dao.CarrierDAO"></bean>最满意答案
将“carrierDAO”的范围设置为“prototype”:
<bean id="carrierDAO" class="ar.com.anovo.dao.CarrierDAO" scope="prototype" />一旦需要注射,这将创建一个新实例。
有关范围的更多信息,请参阅Spring Doc 。
Set the scope of "carrierDAO" to "prototype":
<bean id="carrierDAO" class="ar.com.anovo.dao.CarrierDAO" scope="prototype" />This will create a new instance, once an injection is required.
More about scopes can be found in the Spring Doc.
更多推荐
carrierRESTWS,dao,carrierDAO,bean,电脑培训,计算机培训,IT培训"/> <meta name=&
发布评论