@Reference注解引发错误
@Autowired 写错成了@Reference,因此无法注入对象,导致服务无法启动。 错误原因: The @Reference undefined interfaceClass or interfaceName, and the type com.xxxx.testtest is not a interface. @Reference注入暴露的服务,标记的是作为消费方需要注入的提供方定义的接口实例,直接标记类会报BeanCreationException异常
注入注解 1.@Autowired
org.springframework.beans.factory.annotation.Autowired SpringBoot项目中常用。简单来说就是引入由Spring容器管理的bean。
2.@Resource
javax.annotation.Resource 作用相当于@Autowired,只不过@Autowired是byType自动注入,而@Resource默认byName自动注入。 1.可以定义在类中的一个字段上,也可以定义在一个方法上,甚至可以用来修饰另一个 annotation,表示一个服务的引用。通常 @Reference 定义在一个字段上 2.interfaceClass:指定服务的 interface 的类 3.interfaceName:指定服务的 interface 的类名 4.version:指定服务的版本号 5.group:指定服务的分组 6.url:通过指定服务提供方的 URL 地址直接绕过注册中心发起调用 7.application:应用配置 8.module:模块配置 9.consumer:服务消费方配置 10.protocol:协议配置 11.monitor:监控中心配置 12.registry:注册中心配置
3.@Reference
org.apache.dubbo.config.annotation.Reference @Reference是dubbo的注解,注入的是分布式的远程服务的对象,需要dubbo配置使用。
@Reference注入的是分布式中的远程服务对象,@Resource和@Autowired注入的是本地spring容器中的对象。
