These are chat archives for spring-cloud/spring-cloud

29th
Aug 2017
Tommy Ludwig
@shakuzen
Aug 29 2017 09:50
Regarding spring-cloud/spring-cloud-config#616, are there definite plans for the SCS team to contribute back the implementation they made?
Dave Syer
@dsyer
Aug 29 2017 09:59
Nothing definite.
I thought there was a PR in the pipeline at one point, but it doesn't seem to have materialized.
There is already a CompositeEnvironmentRepository in master though
Is it just the configuration model that's missing?
Tommy Ludwig
@shakuzen
Aug 29 2017 10:02
I’m not sure. I haven’t looked into the code yet, but from the issue it seems perhaps the configuration is just missing (it was designed in such a way it assumed unique repository types?)
Dave Syer
@dsyer
Aug 29 2017 10:03
I don't think there's anything stopping you from creating multiple beans of type EnvironmentRepository and configuring them however you like.
But that would mean a fixed number of repositories.
I guess that's the difference?
Your "fallback" style requirement might work out fine with a fixed number of repositories (one for "general" defaults, and one for application-specific config)
Tommy Ludwig
@shakuzen
Aug 29 2017 10:05
Yes, that’s a decent alternative. I’ll see if I have some time to look into that issue further tomorrow. If it’s a relatively easy change, maybe I’ll just go ahead and work up a PR.
Matthew Planchant
@mplanchant
Aug 29 2017 10:48

Hello all, from the Spring Cloud docs:

The FooConfiguration has to be @Configuration but take care that it is not in a @ComponentScan for the main application context, otherwise it will be used for every @FeignClient. If you use @ComponentScan (or @SpringBootApplication) you need to take steps to avoid it being included (for instance put it in a separate, non-overlapping package, or specify the packages to scan explicitly in the @ComponentScan).

How do I exclude my configuration classes when I'm using @SpringBootApplication?

James Howe
@OrangeDog
Aug 29 2017 10:49
By adding @ComponentScan
Matthew Planchant
@mplanchant
Aug 29 2017 10:51
and an exclude filter?
James Howe
@OrangeDog
Aug 29 2017 10:53
that would work
Matthew Planchant
@mplanchant
Aug 29 2017 11:00
Thanks
Matthew Planchant
@mplanchant
Aug 29 2017 12:18
So something like:
@FeignClient(name = "my-service", configuration = FirstClientConfiguration.class)
@RequestMapping("/my-service")
public interface FirstClient {
    ...
}

@SpringBootApplication
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = FirstClientConfiguration.class),
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = SecondClientConfiguration.class)})
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrix
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
?
Dave Syer
@dsyer
Aug 29 2017 12:20
Sort of. Something like that.
But @SpringBootConfiguration also includes a @ComponentScan with no filters.
So I expect it won't work quite like that
Matthew Planchant
@mplanchant
Aug 29 2017 12:20
With config:
@Configuration
public class FirstClientConfiguration {
    private final ObjectFactory<HttpMessageConverters> messageConverters;

    @Autowired
    public FirstClientConfiguration(ObjectFactory<HttpMessageConverters> messageConverters) {
        this.messageConverters = messageConverters;
    }

    @Bean
    public ErrorDecoder feignErrorDecoder() {
        return new FirstErrorDecoder(new SpringDecoder(this.messageConverters));
    }
}
Dave Syer
@dsyer
Aug 29 2017 12:21
It's easier, honestly, just to put the feign configuration in a different package (one that isn't scanned by default)
Matthew Planchant
@mplanchant
Aug 29 2017 12:22
Which packages aren't scanned by default? Do I create one and then exclude it?
Dave Syer
@dsyer
Aug 29 2017 12:23
Spring Boot scans from the "main" class (the one with @SpringBootApplication)
You might want to vote for this as well: https://jira.spring.io/browse/SPR-14008
It would make life easier for this kind of use case.
Matthew Planchant
@mplanchant
Aug 29 2017 12:25
So the configuration class should not be in a package which is sub package of the package containing the SpringBootApplciation?
Dave Syer
@dsyer
Aug 29 2017 12:25
That's the easiest way to do it IMO
Matthew Planchant
@mplanchant
Aug 29 2017 12:26
It kind of makes a mess of my package hierarchy :-)
Dave Syer
@dsyer
Aug 29 2017 12:27
Yeah. It can result in some rather artificial package structures. That's why SPR-14008 is important.
Matthew Planchant
@mplanchant
Aug 29 2017 12:27
Thanks for the assistance anyway

BTW, can you see any issues with:

@Bean
    public ErrorDecoder feignErrorDecoder() {
        return new FirstErrorDecoder(new SpringDecoder(this.messageConverters));
    }

?

I have this in each of my configuration classes
Dave Syer
@dsyer
Aug 29 2017 12:39
I don't know enough about Feign to know if that is good, bad or indifferent.
If it's really in all of them though, don't you need to put it in the parent?
Matthew Planchant
@mplanchant
Aug 29 2017 12:43
Yes, I think I'm going to try to rewrite this to use a single decoder