The remote Spring Boot application is still connecting to my local mysql

I am working with Angular 4, Spring Boot and Mysql. Local, everything works fine. I am trying to deploy to a remote server, Centos 7. Everything works fine except that when I access my site, it pulls data from my local database, not from the mysql database located on the remote server.

I tried on another computer and the result is the same, it takes data from the local computer!

Here is my Spring boot.properties boot file:

server.port = 8081
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useSSL=false
spring.datasource.username=username
spring.datasource.password=password

      

netstat -tln

on a remote server (only useful fields):

Proto Recv-Q Send-Q local address           remote address          State       
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp6       0      0 :::8081                 :::*                    LISTEN 

      

Mysql databases have exactly the same structure and the same username / password.

- UPDATE -

Thanks for the suggestions, I have finally resolved this issue. It came from the relationship between Angular and Spring, not Spring and Mysql.

The Springboot instance was running on my local machine and the remote Angular was connected to it. In the Angular config file I replaced apiUrl=localhost:8081

with apiUrl=<my remote IP>:8081

, deploy again, I opened port 8081 (Springboot port) to everyone and now it works well.

But honestly, I don't like this method because my Springboot application is available to everyone, whereas it should only be available to an Angular application. If anyone has a solution, this question is still open. Thanks to

+3


source to share


2 answers


Not sure if I think you need to specify the url of the data source in a remote location. Example:



database.url=jdbc:mysql://192.168.0.166:3306/yourSchema?characterEncoding\=UTF-8
database.username=username
database.password=password
database.driverClassName=com.mysql.jdbc.Driver

      

+1


source


due to wrong password - instead mysql complains about the password, it shows an error connecting to local IP, double check your password



0


source







All Articles