我在-servlet中访问我的Controller时注入了一个类,在Controller中为这个类设置值,最后将一个对象返回页面,当单个用户访问时,是没有问题的,但多个用户并发访问就回数据混乱,我怀疑时这个注入的类每次没有被实例.所有用户只访问一个实例导致.跪求解决方法...<bean id="articleController" class="com.comm.article.web.articleController">
<property name="methodNameResolver">
<bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/showArticleList">showArticleList</prop>
</props>
</property>
</bean>
</property>
<property name="articleInterface" ref="articleInterface"/>
</bean>
<bean id="articleInterface" class="com.comm.article.articleInterface">
<property name="dataSource" ref="dataSource"/>
</bean>
<property name="methodNameResolver">
<bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/showArticleList">showArticleList</prop>
</props>
</property>
</bean>
</property>
<property name="articleInterface" ref="articleInterface"/>
</bean>
<bean id="articleInterface" class="com.comm.article.articleInterface">
<property name="dataSource" ref="dataSource"/>
</bean>
最后将注入的类中的数据返回页面.
当单个用户访问时,是没有问题的,但多个用户并发访问就回数据混乱,我怀疑时这个注入的类每次没有被实例.所有用户只访问一个实例导致<bean id="articleController" class="com.comm.article.web.articleController">
<property name="methodNameResolver">
<bean class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/showArticleList">showArticleList</prop>
</props>
</property>
</bean>
</property>
<property name="articleInterface" ref="articleInterface"/>
</bean>
<bean id="articleInterface" class="com.comm.article.articleInterface">
<property name="dataSource" ref="dataSource"/>
</bean> 如果将代码改为,不注入新类,每次在Controller内new一下这个实例(articleInterface),再将值set进去,然后返回页面就好了.
导致数据有冲突,再者如果,你怀疑不是singleton="true"
那么在articleInterface实现类构造函数里加个log看一下
但我认为跟你singleton是否为true关系不大