服务处理接口错误

服务处理接口错误

本文介绍了Spring Boot Cloud Foundry错误中没有唯一的服务处理接口错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循本教程以在Cloud Foundry中运行我的spring boot应用程序。我在本地安装了bosh-lite

I am trying to follow this tutorial https://github.com/cf-platform-eng/spring-boot-cities/tree/master/cities-service to run my spring boot application in Cloud Foundry. I have local bosh-lite installation

我的Spring Boot应用程序以数据库身份连接到postgresql。我正在尝试连接到在本地(主机)上运行的Postgresql实例

My Spring Boot application connects to postgresql as database. I am trying to connect to the Postgresql instance running on my local (host machine )

如果部署到本地tomcat,我的应用程序在本地可以正常运行。
但是,当我将应用程序部署到bosh-lite时,它将失败,并显示以下错误无唯一服务处理接口错误。我的代码与本教程中提到的完全相同,只是我使用Maven来构建代码。

My application works fine locally if deployed to a local tomcat.But when i deploy the app to bosh-lite it fails with the following error "No unique service maching interface error ". My code is excatly the same as what is mentioned in the tutorial except i am using Maven to build my code.

    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中正常读取值,则同一个应用程序可以正常工作。

My connection to postgres works fine. And the same app works fine if i don't use spring cloud connector and read the value normally from application.properties.

我的pom.xml`(具有spring依赖项引导云连接器和postgrsql驱动程序)

My pom.xml`(Has dependencies for spring boot cloud connector and postgrsql driver )

<?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网址。
现在我的应用程序失败,并出现以下错误

[UPDATE]as per Scott's answers below i had a look at the requirements for a UPS to be picked up cloud connector.Since mine is an user provided provided service so i cannot have tags and label. But i added the jdbc urls.Now my app is failing with the below error

 Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

时,为null为此,我设置了我的application.properties中的 spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect ,但仍然不起作用

For this i have set "spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect" in my application.properties but still it does not work

我还检查了我的数据库是否正在运行,并且服务实例中的数据库设置是否正确。

I have also checked that my DB is running and db settings in my service instance is correct.

下面是我的服务实例内容`

Below is my service instance content`

"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

`Best Regards,Saurav

推荐答案

如果包含 spring-boot-starter-cloud-connectors 作为依赖项,然后Spring Cloud Connectors将尝试创建连接数据库所需的 java.sql.DataSource bean。连接器通过查找具有服务绑定来实现此目的= http://cloud.spring.io/spring-cloud-connectors/spring-cloud-cloud-foundry-connector.html#_postgresql rel = nofollow noreferrer>某些特征。 找不到唯一的服务匹配接口javax.sql.DataSource 消息表示连接器找不到适当类型的服务绑定。

If you include spring-boot-starter-cloud-connectors as a dependency, then Spring Cloud Connectors will attempt to create the java.sql.DataSource bean necessary to connect to the database. Connectors does this by looking for a service binding that has certain characteristics. The No unique service matching interface javax.sql.DataSource found message means that Connectors couldn't find a service binding of the appropriate type.

如果要在该示例应用程序中使用连接器,则需要创建,其中包含Postgres连接的详细信息,并将该服务实例绑定到应用程序。

If you want to use Connectors as in that sample app then you will need to create a user-provided service instance with the details of the Postgres connection and bind that service instance to the app.

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

Alternatively, you could remove the spring-boot-starter-cloud-connectors dependency and instead configure the database connection using spring.datasource properties in application.yml.

这些选项在。

这篇关于Spring Boot Cloud Foundry错误中没有唯一的服务处理接口错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 06:42