首页 > 其他分享 >@enableFeignClients注解的basePackages属性的作用

@enableFeignClients注解的basePackages属性的作用

时间:2023-05-04 16:36:18浏览次数:32  
标签:basePackages enableFeignClients module 模块 注解 EnableFeignClients 属性

basePackages 属性是 @EnableFeignClients 注解的一个可选属性,它用于指定需要扫描的包路径。通过设置该属性,可以告诉 Spring 在哪些包下查找用 @FeignClient 注解标记的接口。

basePackages 中的包可以指定其他模块的包。在多模块的项目中,如果你想要在一个模块中使用另一个模块的 Feign 客户端,可以在 @EnableFeignClients 注解中指定其他模块的包路径。只要确保项目之间的依赖关系正确设置,这样就可以让 Spring 扫描并创建所需的 Feign 客户端。

例如,假设你有两个模块:module-a 和 module-b。module-a 中有一个包 com.example.modulea.service,包含使用 @FeignClient 注解的接口。现在你想在 module-b 中使用这些 Feign 客户端。你可以在 module-b 的启动类中,将 basePackages 设置为 module-a 中的包路径,如下所示:

@EnableFeignClients(basePackages = "com.example.modulea.service")
@SpringBootApplication
public class ModuleBApplication {
    public static void main(String[] args) {
        SpringApplication.run(ModuleBApplication.class, args);
    }
}

确保 module-b 依赖于 module-a,这样它就可以访问 module-a 中的类和接口。在 Maven 或 Gradle 配置文件中添加相应的依赖项,以确保正确设置项目间的依赖关系。

标签:basePackages,enableFeignClients,module,模块,注解,EnableFeignClients,属性
From: https://www.cnblogs.com/FengZeng666/p/17371642.html

相关文章

  • springboot 切面注解方式 记录日志
    1.定义GateOpLogimportjava.lang.annotation.*;/***操作日志记录*@authorcodefulture*/@Target({ElementType.METHOD,ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic@interfaceGateOpLog{/***说明*/Strin......
  • lombok的@Builder注解
    lombok的@Builder注解:链式构建一个对象Student.builder().sno("001").sname("admin").sage(18).sphone("110").build();......
  • @Import注解原理源码分析
    文章结构@Import注解源码的入口位置@Import注解原理收集@Import注解处理收集的imports@Import注解源码的入口位置源码的入口位置在ConfigurationClassParser#doProcessConfigurationClass方法中,至于为什么是这个位置,先按下不表后续会填坑完善。Spring如何解析配置类先简单看下Spr......
  • Java 注解
    什么是Java的注解如何在Java中定义一个注解注解通过@interface关键字进行定义。public@interfaceTestAnnotation{}上面的代码就创建了一个名字为TestAnnotaion的注解。那么如何使用这个注解呢?下面的代码创建一个类Test,然后在类定义的地方加上@TestAnnotation......
  • Spring 常用注解
    @ComponentScan@Controller,@Service,@Repository注解,他们有一个共同的注解@Component。@ComponentScan注解默认就会装配标识了@Controller,@Service,@Repository,@Component注解的类到spring容器中。包扫描的方式会比通过@Bean注解的方式方便很多。用法总结:自动扫描路......
  • springboot整合rabbbitmq--注解方式+yml配置
    maven依赖<!--rabbitmq--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!--mail依赖-->......
  • springboot常用注解
    ......
  • SpringMVC使用注解开发
    1.编写web.xml(模板代码)ViewCode2.导入springmvc的context和mvc两个依赖,通过context标签可以自动扫描识别包"com.lian.controller"下的所有注解,两个mvc标签是默认配置;context和mvc分别替代了之前的处理器映射器HandleMapper和处理器适配器HandlerAdapter;视图解析器拼接要要跳转......
  • JPA之@EnableJpaAuditing注解
    在SpringJPA中,支持在字段或方法上进行注解@CreateDate、@CreatedBy、@LastModifiedDate、@LastModifiedBy。具体含义:**@CreateDate:**表示该字段是创建时间字段,在这个实体被insert的时候,会自动填充创建的时间,不用手动填充该字段。**@CreatedBy:**表示该字段是创建人字段,在这......
  • aop实现日志记录通过自定义注解方式
    切面类切入点引入注解@Pointcut("@annotation(com.test.aop.MyLog)")privatevoidpointcut(){}注解类@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)//指定实现的类型及运行时机public@interfaceMyLog{}在使用的方法上加自定义注解@MyLog方法log.i......