1

So I used boxfuse to deploy a spring-boot project to the AWS EC2 service. everything went fine. However, When I access my web-app, the app itself displays an sql exception :

Error querying database. Cause: org.postgresql.util.PSQLEception:ERROR:relation "table" does not exist

Now the webapp does the following: it connects to a psql database and queries some stuff on one of the tables. On my localhost, everything runs perfectly fine. Now for the deployement, the webapp is to use an AWS RDS Psql Database. So I changed the app properties to list the access data for the RDS DB instead of the local one, and deployed to the cloud through boxfuse. By application.properties file for spring looks like this:

spring.datasource.url=jdbc:postgresql://ec2instance:portnumber/Database
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=org.postgresql.Driver

In the spring project pom.xml file, the relevant dependencies are present

<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-aws-jdbc -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-jdbc</artifactId>
<version>1.1.3.RELEASE</version>
</dependency>

What am I missing? I though that maybe I needed to manually SSH into the BoxfuseEC2 instance to install postgresql (might this be the issue?), but I can't SSH due to the limited BoxFuse access-right within the cloud environement.

The boxfuse logfile (last lines) render the following:

2016-10-29 18:46:23.904  INFO 900 --- [nio-8080-exec-6] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2016-10-29 18:46:24.052  INFO 900 --- [nio-8080-exec-6] o.s.jdbc.support.SQLErrorCodesFactory    : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2016-10-29 18:46:24.096 ERROR 900 --- [nio-8080-exec-6] com.vaadin.server.DefaultErrorHandler    : 

org.springframework.jdbc.BadSqlGrammarException: 
### Error querying database.  Cause: org.postgresql.util.PSQLException: ERROR: relation "tablename" does not exist
Position: 14
### The error may exist in com/example/Service.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT * FROM"tablename"ORDER BY x;
### Cause: org.postgresql.util.PSQLException: ERROR: relation "tablename" does not exist
Position: 14 ; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: relation "tablename" does not exist
 Position: 14
   at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) ~[spring-jdbc-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
   at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
   at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) ~[mybatis-spring-1.3.0.jar!/:1.3.0]
[.........]

Anyone have an idea? It seems to me like this is a Postgresql driver + Spring-boot + aws connectivity issue... Maybe something with mybatis? Kinda struggling here....

Spade Johnsson
  • 522
  • 2
  • 7
  • 23

1 Answers1

0

The issue seems to be that your database is empty, yet your application expects certain tables to be present.

Have a look at a database migration tool like Flyway, for which Spring Boot also offers great integration. This lets your application automatically created the database structures it requires on startup.

Axel Fontaine
  • 34,542
  • 16
  • 106
  • 137
  • ACtually the database is full with literaly thousands of entries - using ssh tunneling, I can connect from localhost to it without any issue. From any EC2 Instance, I can access it as well without any issue and query everything! – Spade Johnsson Oct 30 '16 at 09:47
  • If what you want is to use your own existing database instead of the Boxfuse auto-created one, they easiest is to detroy your existing Boxfuse app and recreate it with `-db.type=none` (see https://boxfuse.com/docs/payloads/springboot#databases) – Axel Fontaine Oct 31 '16 at 13:19