繁体   English   中英

在 spring 中将会话范围应用于 bean 时出错

[英]Error while applying session scope to a bean in spring

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

mvc-dispacher-servlet.xml 中的 schema 如下:

<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]

行。 如果它是一个普通的 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

否则你应该很容易通过谷歌找到一些关于这个主题的教程。

很可能你在 bean 之外有一个 bean 范围的选项(我犯了这样的错误并得到了一个像你这样的错误消息):

<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 有这样的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM