因此,我使用boxfuse将spring-boot项目部署到AWS EC2服务。一切都很顺利。然而,当我访问我的web应用程序时,应用程序本身显示了一个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有关的?在这里有点挣扎……
发布于 2016-10-30 17:44:15
问题似乎在于您的数据库是空的,而您的应用程序却希望某些表存在。
看看像Flyway这样的数据库迁移工具,Spring Boot也为其提供了很好的集成。这使您的应用程序可以在启动时自动创建所需的数据库结构。
https://stackoverflow.com/questions/40322083
复制相似问题