Spring mvc @作用域(“请求”)不起作用,SpringMVC仍然返回一个单例

Spring mvc @作用域(“请求”)不起作用,SpringMVC仍然返回一个单例,spring-mvc,web-applications,scope,request,singleton,Spring Mvc,Web Applications,Scope,Request,Singleton,SpringMVC返回“Singleton”对象时出现问题,从而将所有字段暴露给多个(同时)web请求。 我试图将作用域更改为“request”,这样就可以获得控制器/服务和dao对象的新实例,但我无法按照HTTP请求使其工作 下面是我的DAO、控制器、服务和域对象的代码示例 @Component @Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode =ScopedProxyMode.TARGET_CLASS) public

SpringMVC返回“Singleton”对象时出现问题,从而将所有字段暴露给多个(同时)web请求。 我试图将作用域更改为“request”,这样就可以获得控制器/服务和dao对象的新实例,但我无法按照HTTP请求使其工作

下面是我的DAO、控制器、服务和域对象的代码示例

@Component
@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode    =ScopedProxyMode.TARGET_CLASS)
public class CountDaoImpl implements CountDao {

private static final long serialVersionUID = 1L;
private static Connection conn = null;

}

@Controller(value="countController")
@RequestMapping("VIEW")
@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode =ScopedProxyMode.TARGET_CLASS)
public class CountController {

@Autowired
@Qualifier("CountServiceImpl")
CountService CountService; 
.
.
.
 }

@Service("CountServiceImpl")
@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode     =ScopedProxyMode.TARGET_CLASS)
public class CountServiceImpl implements CountService {

@Autowired
@Qualifier("countDaoImpl")
private  CountDao  CountDao;
}

@Component
@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode =ScopedProxyMode.TARGET_CLASS)
public class Count implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 9931247627087666L;
private Owners owners;
.
.
.
.
.
.
}

下面是我的web.xml,它具有“RequestContextListener”,正如在


PortletApp
0
http://java.sun.com/portlet_2_0
/WEB-INF/tld/liferay-portlet.tld
http://liferay.com/tld/aui
/WEB-INF/tld/aui.tld
log4jConfigLocation
/WEB-INF/classes/log4j.properties
org.springframework.web.context.request.RequestContextListener
视图servlet
org.springframework.web.servlet.viewRenderServlet
1.
视图servlet
/WEB-INF/servlet/view
下面是“countportlet.xml”


我想为上面每个类的每个HTTP请求创建一个对象。
有人能告诉我哪里出了问题吗?

我知道有点晚了,但我希望这能帮助别人

@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode =ScopedProxyMode.INTERFACES)

我猜是因为我所有的类都实现了我使用这种代理模式的接口。

定义“不工作”。你的代码在做什么?你预计会发生什么?会发生什么情况呢?两个单独的HTTP请求获取相同的对象,因此两个请求都可以看到字段。如果两者都是同时请求,Request2经常会遇到关闭的连接/结果集,因为Request1在完成其工作后关闭了这些连接/结果集。我希望每个http请求都创建一个单独的对象,这样两个同时发生的请求就不会相互冲突。这就是我切换到@scope(“请求”)的意图。。。但是使用{@Scope(value=WebApplicationContext.Scope\u REQUEST,proxyMode=ScopedProxyMode.TARGET\u CLASS)}并没有什么区别,它确实做到了。谢谢
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util-3.0.xsd
        ">
    <context:annotation-config />
    <context:component-scan base-package="com.company.count" />
    <bean class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>


    <bean id="viewResolver" 
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>
@Scope(value=WebApplicationContext.SCOPE_REQUEST, proxyMode =ScopedProxyMode.INTERFACES)