在春季将会话范围应用于bean时出错

问题描述 投票:0回答:2

我试图使用@Scope注释更改bean的范围。该bean实际上是作为MessageSource并用于国际化目的。

mvc-dispacher-servlet.xml中的架构如下:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
    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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

控制台中描述的异常如下:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionParser for element [scoped-proxy]

java spring session spring-annotations
2个回答
0
投票

好如果它是普通的bean,则很可能您只是缺少了作用域标记的xml解析器。为了能够使用作用域代理,您需要注册aop:scoped-proxy。

关于SO有类似的问题:Accessing a session-scoped bean inside a controller

将导致:

http://static.springsource.org/spring/docs/3.0.x/reference/beans.html#beans-factory-scopes-other-injection

否则,您应该可以通过Google轻松找到有关此主题的一些教程。


0
投票

很可能您在bean之外有一个bean范围的选项(我犯了这样的错误,并收到了像您一样的msg错误):

<beans>
...
<aop:config proxy-target-class="true"/>
<aop:scoped-proxy proxy-target-class="true"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
...

只需将该选项放在bean声明中:

<bean ... target="step">
    <aop:scoped-proxy proxy-target-class="true"/>
</bean>

另外一件事-我仅对作用范围内的bean出现了这样的错误。

© www.soinside.com 2019 - 2024. All rights reserved.