gpt4 book ai didi

spring - Spring Boot Cloud Foundry 报错 No unique service maching interface 报错

转载 作者:行者123 更新时间:2023-11-29 12:55:31 26 4
gpt4 key购买 nike

我正在努力学习本教程 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 时,它​​失败并出现以下错误“没有唯一的服务处理接口(interface)错误”。除了我使用 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 的连接工作正常。如果我不使用 spring cloud connector 并正常从 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>

`

[更新]根据下面 Scott 的回答,我查看了 UPS 被拾取云连接器的要求。因为我的是用户提供的服务,所以我不能有标签和标签。但我添加了 jdbc url。现在我的应用程序因以下错误而失败

 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": []
}
]
}

`此致,索拉夫

最佳答案

如果您将 spring-boot-starter-cloud-connectors 作为依赖项,那么 Spring Cloud Connectors 将尝试创建 java.sql.DataSource bean连接到数据库。连接器通过寻找 service binding 来做到这一点有 certain characteristics . No unique service matching interface javax.sql.DataSource found 消息表示连接器无法找到适当类型的服务绑定(bind)。

如果您想像在该示例应用程序中那样使用连接器,则需要创建一个 user-provided service instance使用 Postgres 连接的详细信息并将该服务实例绑定(bind)到应用程序。

或者,您可以删除 spring-boot-starter-cloud-connectors 依赖项,而是使用 application 中的 spring.datasource 属性配置数据库连接。 yml

这些选项在 blog post 中有更详细的解释。 .

关于spring - Spring Boot Cloud Foundry 报错 No unique service maching interface 报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44418856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com