0

I am trying to create a war file using spring boot and to deploy on a remote secured linux vm where postgres sql is installed,I want to use services to get data(read only operations) from db.

I had written code for this and used below application.properties:

 spring.datasource.url=jdbc:postgresql://localhost/test  ---localhost refers to the remote linux vm here
 spring.datasource.username=test
 spring.datasource.password=test
 spring.jpa.generate-ddl=true

Now,when I do a maven install to generate war file,I am getting below exception:

 2017-04-25 04:49:36.588  INFO 9184 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
 2017-04-25 04:49:38.084 ERROR 9184 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

 org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
   at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]

Probably,its trying to connect to my localhst for getting postgres sql db details,but I want this to connect to remote linux vm,need pointers on this.

Anand
  • 621
  • 3
  • 9
  • 31
  • Are you able to connect to postgres normally on port 5432? – yaswanth Apr 25 '17 at 12:19
  • yes,i can connect to postgres by logging on remote linux vm and by running "su - postgres" – Anand Apr 25 '17 at 12:22
  • From the error, I think it's not able to connect to postgres on that port. This question has listed in detail all possibilities that can happen. http://stackoverflow.com/questions/20825734/postgresql-connection-refused-check-that-the-hostname-and-port-are-correct-an – yaswanth Apr 25 '17 at 12:34
  • yes,this error will come if i try to acess postgressql directly,but i intend to generate a war file and place it on remote machine and use rest calls to get data from the db' – Anand Apr 25 '17 at 12:35
  • 1
    If I am not wrong, why will mvn install run any code? That will just compile the code into class files and create a war. The exception says otherwise. One possibility would be that you have some tests which are running the code. Is that the case? Can you post a detailed stacktrace and put what command you are running? – yaswanth Apr 25 '17 at 12:40
  • 1
    Do you have any integration test??? I see you app is trying to start the actual application context on embedded server. mvn install by default runs mvn test as well – Praneeth Ramesh Apr 25 '17 at 14:51
  • @yashwanth,@Parneeth:indeed i hadnt deleted the integration test and that was causing problem,thanks for giving pointers :) – Anand Apr 25 '17 at 15:30
  • It is unclear exactly what you are asking. You have built a WAR and deployed it on your local machine? You want it to connect to some remote DB? Then why is the DB URL pointing to localhost? What maven command exactly are you running as `mvn install` simply builds a WAR. – Alan Hay Apr 25 '17 at 18:17
  • @Alan:problem is fixed,I was using maven install but hadnt removed integration test,so it was trying to point to my localhost postgres db rather than the remote linux postgres db – Anand Apr 26 '17 at 05:30

0 Answers0