Java Spring Bean不需要类型异常

Java Spring Bean不需要类型异常,java,spring,spring-aop,Java,Spring,Spring Aop,我有这样的豆子: <bean id="myBean" class="com.mypackage.MyClass" scope="session"> </bean> 我得到了这个错误: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myBean' must be of type [com.mypackage.GenericClass], but was actua

我有这样的豆子:

<bean id="myBean" class="com.mypackage.MyClass" scope="session">
</bean>
我得到了这个错误:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myBean' must be of type [com.mypackage.GenericClass], but was actually of type [com.sun.proxy.$Proxy118]
我补充道:

<aop:scoped-proxy />

在我的bean声明中,但我喜欢理解我在做什么,在这种情况下我不理解

你能解释一下为什么我会遇到这个异常,为什么添加
可以解决这个问题吗

谢谢

通过添加


编辑1:实际上,使用基于CGLib(AspectJ)的代理是默认选项。这可能就是解决问题的方法。

如果从bean定义中删除
scope=“session”
,也不会出现异常。是的,但我需要这个bean成为会话范围。当然,您需要
,因为在纯
applicationContext.getBean
的情况下,没有HTTP会话来绑定您的bean。
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myBean' must be of type [com.mypackage.GenericClass], but was actually of type [com.sun.proxy.$Proxy118]
<aop:scoped-proxy />