ClassCastException $Proxy cannot be cast to using aop

前端 未结 1 1781
名媛妹妹
名媛妹妹 2020-12-16 06:11

I was using spring to create objects through beans. Now I tried to use aop to create the same object and I get $Proxy cannot be cast to SaleRoom exception.

the previ

相关标签:
1条回答
  • 2020-12-16 06:32

    Does your SaleRoom class implement some interface? If yes, then you should use interface and not class in you code:

    ISaleRoom saleRoom = (ISaleRoom) context.getBean(saleName);
    

    Because if your bean implements some interface then Spring by default will create proxy based on this interface.

    Here is a good article about proxy creation in Spring.

    Also you can change proxying mechanism for Spring AOP if you want to create proxy for target class. This is described here in reference documentation.

    0 讨论(0)
提交回复
热议问题