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.
Related
We are using grpc spring boot starter on our Java application service in order to establish a connection to another 'server' service, so I define in the application.properties the following address:
grpc.client.name.address=static://service-name:port
When tried to connect it I got the following error message:
StatusRuntimeException: UNAVAILABLE: io exception
So I know for sure I have a connectivity issue. On the documentation it says regarding the static scheme:
A simple static list of IPs (both v4 and v6), that can be use connect to the server
So I guess this is not what I need to use. It seems the best option in my case is using the discovery scheme, but it doesn't contains any port...
What is the right scheme configuration I need to use to set the server address?
Wanted to share the resolution for this very annoying issue for those who will encounter the same problem in the future like I did.
So first, the scheme needs to be set indeed of dns type, like the following: grpc.client._name_.address=dns:///<service-name>:26502
but this alone is not enough. (at least in my case) The server was configured to run in PLAINTEXT, while my client, by default, was configured to run with TLS mode, so it must be set with grpc.client.__name__.negotiationType=PLAINTEXT property.
See the following documentation for further information
It caused by gRPC can't resolve addresss service-name:port;
If you use static, the value must be ip:port; The service-name need to be resolved as ip address;
If you are using register center like consul or eureka etc., you should use discovery:///service-name without specify port.
If you didn't use register center, only end to end with server, replace service-name as a ip like 127.0.0.1 which belong to server;
Or modify host config for parse service-name like below, the file on Linux is /etc/hosts
127.0.0.1 service-name
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 am connected to dormitory subweb. I have 2 machines with external ip adresses. ( I am able to ping them or connect with them via SSH) Raspberry Pi running ubuntu mate where my Spring Boot server is hosted and other machine running Windows 10. Problem is that Spring server do not respond to requests from any source beside dormitory web (DW). I found that Issue is 8080 port closed. when I scan for open ports from beside DW I can only see 22 port opened, Computers inside DW see 8080 and 22 ports as opened and are able to respond HTTP server.
From what I have read here I have to set server.address property to be accessible from "outside"
My spring application.properties
#mysql test config
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver`
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.DefaultNamingStrategy
#initialization
spring.datasource.schema=classpath:/data/schema.sql
#server
server.address= my.adres.here
server.port = 8080
I am sure that sever reads this file properly.
I also tried turn off firewall temporarily
sudo ufw disable
to check if it blocks connection on this port but thats not the issue.
I am not sure where the real problem may be localized. Could it be something wrong with Spring Boot config? Or maybe it is some networking issue.
as #Robert Masen suggested problem was dormitory network blocking connection on 8080 port.
I'm trying to use Port 80 as a non-root user and I've seen the discussions about using IP Tables but I'd like to use the tomcat configuration files to be able to modify these bindings. There is an option for AUTHBIND that allows using ports <1024 but I have no idea where the Spring tomcat files are located... There is no tomcat service running when I start my Spring process so where is the Spring tomcat server actually located? Where can I see the configuration files etc?
I think you have a wrong approach. I don't recommand you to try to use HTTP port 80 directly.
A good practice is to use Apache HTTP Server redirection or alias :
Here's a tutorial
Explaination :
You will start your Tomcat with "classic" port (such as 8080 or 9080 or anything else over 1024). Then, you will configure your Apache server to redirect HTTP request from HTTP port 80 to your Tomcat server.
Do follow steps:
1. Go to your application.properties if it doesn't exist.
2. Create a application.properties inside src/main/resources folder.
example->/src/main/resources/application.properties
3. Simply add this property server.port = 80 or if you want it to be random do server.port = 0
I am using spring boot to listen for messages on my rabbitmq instance. I have it working locally using an application.properties file.
However, when I want to connect to the remote rabbit instance I am getting number format exceptions and unknown host exceptions because of my url.
I've tried setting spring.rabbitmq.host to:
amqp://myurl/dev and myurl/dev and amqp%3A%2F%2Fmyurl%2Fdev
Nothing is working. Any ideas what could be up. I have set my user name and pass for the remote instance as well.
Try removing the amqp:// part. The host property should just be that, the hostname:
spring.rabbitmq.host=myurl
Not sure what the /dev part is. Are you saying that is your virtual-host? If so then just set this property too:
spring.rabbitmq.virtual-host=dev
For username/password, set these properties:
spring.rabbitmq.username=
spring.rabbitmq.password=
A better way to do this is to set
spring.rabbitmq.addresses=amqps://user:password#10.0.0.123/virtualhost
This will get auto-resolved, and correctly set your hostname, password etc
Github issue that fixes this:
https://github.com/spring-projects/spring-boot/issues/6401