其他分享
首页 > 其他分享> > Spring Boot 之 spring.factories

Spring Boot 之 spring.factories

作者:互联网

转载至 https://www.cnblogs.com/huanghzm/p/12217630.html

1、抛出一个问题

首先抛出一个问题:如果想要被Spring容器管理的Bean的路径不再Spring Boot 的包扫描路径下,怎么办呢?也就是如何去加载第三方的Bean 呢?

2、解决办法有两个

2.1 使用 @Import 注解

@Import({SwaggerConfig.class})
@Configuration
public class MyConfig {

    @Bean
    public Person person(){
        return new Person();
    }

    @Bean
    public PesonPointcut pesonPointcut(){
        return new PesonPointcut();
    }


}

2.2 使用spring.factories 文件

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
  com.ali.gts.sofa.consumer.SwaggerConfig

3、spring.factories 的位置

META-INF/spring.factories

 

标签:Spring,Boot,Bean,spring,factories,public
来源: https://www.cnblogs.com/gaohq/p/14998928.html