更新时间:2023-08-21 12:13:10
默认情况下,您无法访问实现(PerformanceImp
),因为您启用了AOP,它将设置为目标接口而不是实现.如果您删除EnableAspectJAutoProxy
,您会看到代码可以正常工作.
You cannot access the implementation (PerformanceImp
) by default, because you enabled AOP, which sets to target interfaces instead of implementation. If you would remove EnableAspectJAutoProxy
, you would see the code would work fine.
To understand a bit more about how AOP targeting works, take a look at this Spring Documentation
Spring AOP也可以使用CGLIB代理.这是代理的必要条件 类而不是接口.如果业务是默认情况下,则使用CGLIB 对象未实现接口.因为这是一个好习惯 编程接口而不是类;正常的商务舱 将实现一个或多个业务接口.有可能 在您需要的那些(非常罕见)情况下,强制使用CGLIB 告知未在接口或您所在位置声明的方法 需要将代理对象作为具体类型传递给方法.
Spring AOP can also use CGLIB proxies. This is necessary to proxy classes rather than interfaces. CGLIB is used by default if a business object does not implement an interface. As it is good practice to program to interfaces rather than classes; business classes normally will implement one or more business interfaces. It is possible to force the use of CGLIB, in those (hopefully rare) cases where you need to advise a method that is not declared on an interface, or where you need to pass a proxied object to a method as a concrete type.
因此,您有两个选择:
ApplicationContext
获取Bean时,请使用接口.ApplicationContext
.要执行第2点,请按如下所示修改注释:
To do this point #2, modify your annotation as follows:
@EnableAspectJAutoProxy(proxyTargetClass = true)
原因:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为'entityManagerFactory'的bean可用
NoSuchBeanDefinitionException: 没有名为“entityManagerFactory"的 bean 可用
没有可用的“javax.persistence.EntityManager"类型的合格 bean:预期单个匹配 bean,但发现 2
NoSuchBeanDefinitionException:找不到符合Spring测试和Junit依赖类型的合格Bean
没有可用的“org.springframework.kafka.config.AbstractKafkaListenerContainerFactory"类型的合格 bean
没有可用的“org.springframework.kafka.config.AbstractKafkaListenerContainerFactory"类型的合格 bean