In a microservice system, I have an interface with the annotation @AuthorizedFeignClient(name="send-email", url="http://localhost:8080/utils/api/email")
, in the development environment it works correctly, however, in the Docker environment, I need the url parameter to have the Docker container name in place of localhost to work in the Docker environment.
I tried adding in the application-prod.yml the configuration:
containers-host:
gateway: jhipster-gateway
And in the annotation I put it like this:
@AuthorizedFeignClient(name="send-email", url="http://${containers-host.gateway}:8080/utils/api/email")
However, when trying to generate the .war it fails:
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'com.sistema.service.util.EmailClient' defined in null: Could not resolve placeholder 'containers-host.gateway' in value "http://${containers-host.gateway}:8080/utils/api/email"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'containers-host.gateway' in value "http://${containers-host.gateway}:8080/utils/api/email" 2018-11-08 11:25:22.101 ERROR 64 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'com.sistema.service.util.EmailClient' defined in null: Could not resolve placeholder 'containers-host.gateway' in value "http://${containers-host.gateway}:8080/utils/api/email"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'containers-host.gateway' in value "http://${containers-host.gateway}:8080/utils/api/email"
How can I do to set the hostname of the service according to the configuration of the environment it runs?
My code that is failing looks like this:
@AuthorizedFeignClient(name="send-email", url="http://${containers-host.gateway}:8080/utils/api/email")
public interface EmailClient {
@PostMapping("/send-email")
void sendEmail(String mail);
}
To set the value entered in application-dev.yml or application-prod.yml it is necessary to create a configuration class with the @ConfigurationProperties annotation.
In the .yml file:
Create the configuration file this way:
And make the @AuthorizedFeignClient like this: