我正在尝试按照本教程https://github.com/cf-platform-eng/spring-boot-cities/tree/master/cities-service在Cloud Foundry中运行我的spring boot应用程序.我在本地安装了bosh-lite
我的Spring Boot应用程序作为数据库连接到postgresql.我正在尝试连接到在本地(主机)上运行的Postgresql实例
如果部署到本地tomcat,我的应用程序在本地运行良好.
但是,当我将应用程序部署到bosh-lite时,它将失败,并显示以下错误“无唯一服务处理接口错误”.我的代码与本教程中提到的完全相同,只是我使用Maven来构建代码.
2017-06-07T22:29:54.44+0530 [App/0] OUT Caused by: org.springframework.cloud.CloudException: No unique service matching interface javax.sql.DataSource found. Expected 1, found 0
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.springframework.cloud.Cloud.getSingletonServiceConnector(Cloud.java:149) ~[spring-cloud-core-1.2.3.RELEASE.jar!/:na]
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.saurav.cf.casestudy.employee.db.DataSourceConfiguration.dataSource(DataSourceConfiguration.java:20) ~[classes/:na]
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.saurav.cf.casestudy.employee.db.DataSourceConfiguration$$EnhancerBySpringcglib$$847aab5e.cglib$dataSource$0(<generated>) ~[classes/:na]
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.saurav.cf.casestudy.employee.db.DataSourceConfiguration$$EnhancerBySpringcglib$$847aab5e$$FastClassBySpringcglib$$2ad81e2b.invoke(<generated>) ~[classes/:na]
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
2017-06-07T22:29:54.44+0530 [App/0] OUT at org.saurav.cf.casestudy.employee.db.DataSourceConfiguration$$EnhancerBySpringcglib$$847aab5e.dataSource(<generated>) ~[classes/:na]
2017-06-07T22:29:54.44+0530 [App/0] OUT at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
我与postgres的连接正常.如果我不使用弹簧云连接器并从application.properties中正常读取值,则同一个应用程序可以正常工作.
我的pom.xml`(具有Spring Boot云连接器和postgrsql驱动程序的依赖项)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.saurav.cf.casestudy</groupId>
<artifactId>employeerest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>employeerest</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!-- <start-class>org.saurav.cf.casestudy.employee.EmployeerestApplication</start-class> -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
`
[UPDATE]
根据下面斯科特的答案,我查看了要使用云连接器的UPS的要求.由于我的是用户提供的服务,所以我没有标签和标签.但是我添加了jdbc网址.
现在我的应用失败,出现以下错误
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
为此,我在application.properties中设置了“ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgresqlDialect”,但它仍然无法正常工作
我还检查了我的数据库是否正在运行,并且服务实例中的数据库设置正确.
以下是我的服务实例内容`
"VCAP_SERVICES": {
"user-provided": [
{
"credentials": {
"jdbcUrl": "jdbc:postgresql://10.0.2.2:5432/employee",
"username": "postgres",
"password": "admin",
"postgresUri": "postgresql://10.0.2.2:5432/employee",
"uri": "postgresql://10.0.2.2:5432/employee"
},
"label": "user-provided",
"name": "postgresql-cf-service",
"syslog_drain_url": "",
"tags": [],
"volume_mounts": []
}
]
}
`
最好的祝福,
Saurav
解决方法:
如果您将spring-boot-starter-cloud-connectors作为依赖项包括在内,那么Spring Cloud Connectors将尝试创建连接数据库所需的java.sql.DataSource bean.连接器通过查找具有certain characteristics的service binding来做到这一点.“没有唯一的服务匹配接口javax.sql.DataSource找到”消息表示连接器找不到适当类型的服务绑定.
如果要在该示例应用程序中使用连接器,则需要使用Postgres连接的详细信息创建user-provided service instance并将该服务实例绑定到该应用程序.
另外,您可以删除spring-boot-starter-cloud-connectors依赖关系,而是使用application.yml中的spring.datasource属性配置数据库连接.
这些选项在blog post中有更详细的说明.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。