1

所以我使用 boxfuse 将 spring-boot 项目部署到 AWS EC2 服务。一切顺利。但是,当我访问我的网络应用程序时,应用程序本身会显示一个 sql 异常:

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

现在 webapp 执行以下操作:它连接到 psql 数据库并在其中一个表上查询一些内容。在我的本地主机上,一切运行良好。现在进行部署,webapp 将使用 AWS RDS Psql 数据库。所以我更改了应用程序属性以列出 RDS DB 而不是本地的访问数据,并通过 boxfuse 部署到云端。spring 的 application.properties 文件看起来像这样:

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

在spring项目的pom.xml文件中,存在相关的依赖

<!-- 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>

我错过了什么?我虽然可能需要手动 SSH 到 BoxfuseEC2 实例来安装 postgresql(这可能是问题吗?),但由于云环境中的 BoxFuse 访问权限有限,我无法 SSH。

boxfuse 日志文件(最后几行)呈现以下内容:

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]
[.........]

有人有想法吗?在我看来,这是一个 Postgresql 驱动程序 + Spring-boot + aws 连接问题......也许与 mybatis 有关?在这里有点挣扎......

4

1 回答 1

0

问题似乎是您的数据库是空的,但您的应用程序希望某些表存在。

看看像Flyway这样的数据库迁移工具,Spring Boot 也提供了很好的集成。这让您的应用程序在启动时自动创建所需的数据库结构。

于 2016-10-30T09:44:15.317 回答