spring-cloud/spring-cloud-config

Ehance native backend documentation

andersonfaria-hotmart opened this issue · 14 comments

Documentation says that to use native file backend is necessary to use spring.profiles.active=native.
But if it's necessary to use different profiles (embedded config server with local files for example) it'd be impossible to change behavior for staging or production for example.
In such cases it's possible to use a different profile from native and create a NativeEnvironmentRepository Bean:

@Bean
public NativeEnvironmentRepository environmentRepository(NativeEnvironmentRepositoryFactory factory,
                                       NativeEnvironmentProperties environmentProperties) {
    return factory.build(environmentProperties);
}

Can you provide a more complete example of the problem? I am not sure I understand what the issue or suggestion is.

Documentation does not say about the possibility to create the NativeEnvironmentRepository, only says about the spring.profiles.active=native.
It could help someone else this information. I spent some time to figure out this.

That is true of every bean that is conditionally activated. If the bean is not created for some reason you have the option to create it yourself. We don't typically document those things, we try to document functionality instead.

This documentation could be helpful in cases when someone needs to manage different profiles, as I mentioned. I spent some time figuring it out...

So why not activate multiple profiles?

Well, I tried it, but didn't work. I don't know why but the only way for me was creating the NativeEnvironmentRepository

It should work. In fact we explicitely call that out in the documentation as a way of supporting multiple EnvironmentRepositorys
https://docs.spring.io/spring-cloud-config/reference/server/environment-repository/composite-repositories.html

But that wasn't the problem. The NativeEnvironmentRepository was needed to use one repository (native) with multiple profiles

The additional profiles were unrelated to the config server?

In my specific case I intended to use config server for resource bundles to another apis. But I needed to use it with local files, so I needed to use the profile=native.
I tried to use 2 profiles at the same time (native and production or native and staging) but this didn't work. So I created the NativeEnvironmentRepository and used the desired profile with the respective properties

Can you provide a sample that reproduces the problem?

I'll create a sample project and share it here :)

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.