I created a simple micronaut app in my local with 'consul-config' feature. My code can able to connect and get properties from consul key/value store. I have below configuration in my bootstrap.yml
micronaut:
application:
name: user-service
config-client:
enabled: true
consul:
client:
registration:
enabled: true
defaultZone: "${CONSUL_HOST:localhost}:${CONSUL_PORT:8500}"
Everything is fine but I don't want to use consul in my local computer, because since it involves the network activity so startup takes sometime. I want to avoid consul in local but I need it in dev, test and prod environments.
I have below code in my app. #Value annotation will try to load 'db-schema' and if it not founds then uses 'local' as default value. So if consul is disabled then my app should use 'local' else it should load values based on consul configuration.
#Value("${db-schema:local}")
private String dbSchema;
How I can do this with out code changes and only with environment options?
I tried setting VM option '-Dmicronaut.config-client.enabled=false' but still it loads bootstrap.yml and trying to connect consul.
There are a number of ways you can do it. One is to create a file like src/main/resources/application-local.yml which contains the following:
consul:
client:
registration:
enabled: false
And in your local environment export MICRONAUT_ENVIRONMENTS=local.
Related
i want to integrate the vault on my java micro-service, it has been already integrated for other services in the project . i want to know what are the actions that i have to perform for integrationg it .. currently the steps that i thought for integration are..
1. add the dependency on pom.xml
2. add the key on vault server (dashboard)
3. add this on application.yml
spring.cloud.vault:
host: localhost
port: 8200
scheme: https
uri: https://localhost:8200
connection-timeout: 5000
read-timeout: 15000
config:
spring.config.import: vault://
i want to know these were the only steps for integration or somethings more i have to do
Hello i have an issue after i have added spring mail to my application.These are the app.propreties where the issue is.
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
server.port=${PORT}
this is how i am binding it in the EmailConfig class
#Value("${spring.mail.port}")
private int port;
also this is the mail i am using
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
Every time i start the app i receive this error:
Description:
Failed to bind properties under 'server.port' to java.lang.Integer:
Property: server.port
Value: ${PORT}
Origin: class path resource [application.properties]:20:13
Reason: failed to convert java.lang.String to java.lang.Integer
Action:
Update your application's configuration
For some reason it seems that i cannot make requests on basic 8080 port.So i have modified the server.port to this server.port=${PORT:9191} and it works but i get some requests issue with some of my pages for some reason.
Thing is , i have this same configuration on another application and it works without me having to modify the port to a different number.Why is this happening? i would like to remain on standard port.
Any help would be greatly appreciated !
If you want to remain on standard port, remove the line server.port from your application.properties (so it runs on 8080).
server.port - used to configure the application to run in different port other than standard port.
spring.mail.port - used to configure smtp server port. If your SMTP server is using standard port, you don't need to configure this property.
The other application that has the same configuration would have the PORT value set in either environment variables or system properties. It's not possible to run the application without assigning any value to PORT variable as it is a configuration parameter.
app.properties have server.port property while in the code you try to access ${spring.mail.port} which is empty.
Port 8080 is always returned from eureka no matter what configuration is in the client. Here is an example of my eureka configuration on the client:
This is the application.yml
eureka:
client:
register-with-eureka: true
fetch-registry: false
serviceUrl:
defaultZone: http://eurekaserver.com/eureka
instance:
nonSecurePort: 80
nonSecurePortEnabled: true
hostname: myhost
The application using the above configuration will try to register with eureka. it can successfully register but eureka returns http://myhost.com:8080. The expected url is suppose to be http://myhost.com.
The application runs on port 8080 however the restendpoint is reached by http://myhost.com. is there any way to fix this?
--Edit--
here is my bootstrap.yml
spring:
application:
name: myappname
In which file did you add this config? bootstrap.yml, application.yml, or a profile specific one? Also check for typos in the properties filename.
So what's happening is that your config isn't loaded properly. The auto-configuration of Eureka Client doesn't find an EurekaInstanceConfigBean in the current context, so it's creating one for you.
By default it checks first server.port, then port and eventually it's setting the port to 8080 if previous keys haven't been set.
I didn't know which version you are using, but this has been the default behaviour for quite some time now.
I hope this helps! :)
I'm seeing the exact same behavior. All the clients registered with the server is returned with right url but wrong port number, 8080. I have 2 clients running on the same node with different name and port, the one is really using port 8080 is correctly showed on the eureka server but the one is using port 9090 is somehow also showing port 8080 on eureka server. I have tried to move the server.port to here and there (bootstrap.yml or application.yml) but there's no luck. Any help will be appreiated!
In this case, go to:
Run as -> Run configurations
Environment
Remove the port number 8080 from it and apply
Try to run your application with different port by passing server.port=8081 in application.properties
I had same issue and I have solved setting this parameter on application.properties:
server.port = 7011
It could be redundante (in my case, I get the port from Weblogic) but it is mandatory on Client configuration to avoid to register the service with default port (8080)
I deployed a Spring Boot app on AWS Elastic Beanstalk. I am facing a 502 Bad Gateway error. I cannot find anything useful from the logs
/var/log/nginx/error.log
2019/02/10 02:12:54 [error] 3257#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: ...., server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "...."
I do not have any html files for front-end. I just want to upload deploy the api to share the documentation from swagger ui.
It's because server is listening to 5000, Adding "server.port=5000" to application.properties fixed the issue.
This happens because the application load balancer by default points to the Port 80 of the nginx server in EC2 instance. The nginx is configured to forward requests to Port 5000 by default, whereas out application server runs on Port 8080.
Default Nginx Configuration
Expected Nginx Configuration
This can be fixed using an environment property named PORT and pointing it to 8080
Go to configuration > Environment Properties and add the property
Refer AWS Document: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html
Another option to fix this is to point application load balancer to the application server port(8080) directly instead of the nginx(80.
You can configure 8080 as the process port.
Another way to fix this would be to set port to 5000 in the spring boot application by using server.port property.
My issue was my Java version didn't match the platform I'm running with Elastic Beanstalk, even tho my server.port was on 5000. My Java version was 11, and my platform was only Java 8 for Amazon Linux. So changing it to 8 in my base pom.xml fixed it.
How to make Spring Cloud Consul register with external IP?
I run spring boot applications with spring cloud consul in docker.
The application is running inside a docker network on a docker swarm.
This means that if spring consul registers with the hostname or the IP address it will get an hostname or ip address that is internal to the docker swarm. My consul server is outside the docker swarm.
You can set spring.cloud.consul.discovery.ipAddress externally and set the property spring.cloud.consul.discovery.preferIpAddress=true.
Alternatively, you can control which network interfaces to derive an ip address from.
In Brixton you can ignore interfaces:
spring:
cloud:
inetutils:
ignoredInterfaces:
- docker0
- veth.*
In Camden (currently RC1) you can also whitelist networks:
spring:
cloud:
inetutils:
preferredNetworks:
- 192.168
- 10.0
Run the container with -p 12345:12345 to publish the port so that you can access the container from your host machine through the specified port