Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用vcap服务为spring数据jpa应用程序使用关键的cloudmq和mysql服务_Java_Mysql_Spring_Jpa - Fatal编程技术网

Java 使用vcap服务为spring数据jpa应用程序使用关键的cloudmq和mysql服务

Java 使用vcap服务为spring数据jpa应用程序使用关键的cloudmq和mysql服务,java,mysql,spring,jpa,Java,Mysql,Spring,Jpa,我能够使用pivotal上的RABBITMQ和MYSQLSERVICES。绑定服务时,我能够获取凭据,并在我的application.properties for spring data jpa项目中使用该凭据 但我使用的配置是在应用程序中硬编码的。属性为了动态地进行配置,我知道我们可以使用pivotal提供的vcap服务 因此,我们希望为rabbimq和mysql使用运行时凭据 下面是我的代码供参考 文件:application.properties rabbitmq.host=hostnam

我能够使用pivotal上的RABBITMQ和MYSQLSERVICES。绑定服务时,我能够获取凭据,并在我的application.properties for spring data jpa项目中使用该凭据

但我使用的配置是在应用程序中硬编码的。属性为了动态地进行配置,我知道我们可以使用pivotal提供的vcap服务

因此,我们希望为rabbimq和mysql使用运行时凭据

下面是我的代码供参考

文件:application.properties

rabbitmq.host=hostname
rabbitmq.virtual-host=vhost
rabbitmq.username=username
rabbitmq.password=password
rabbit.mainqueue=queue name
rabbit.errorqueue=erro queue name
spring.datasource.url=jdbc:mysql://hostname:postno
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
server.port=8000
下面是存储库文件

package com.redistomysql.consumer.repo;

import org.springframework.data.jpa.repository.JpaRepository;

public interface tblemployee_personal_infoRepository extends JpaRepository<tblemployee_personal_info, Long> {

}
package com.redistomysql.consumer.repo;
导入org.springframework.data.jpa.repository.JpaRepository;
公共接口tblemployee_personal_informationpository扩展了JpaRepository{
}
任何帮助都将不胜感激

The link for reference **http://www.java-allandsundry.com/2016/05/approaches-to-binding-spring-boot.html** 
Set this configuration in application-cloud.yml for Mysql
---

spring:
  datasource:
    url: ${vcap.services.mydb.credentials.jdbcUrl}
    username: ${vcap.services.mydb.credentials.username}
    password: ${vcap.services.mydb.credentials.password}

    The config for rabbitMq:
System.getEnv("VCAP_SERVICES")
pom.xml中的依赖关系

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-spring-service-connector</artifactId>
        <version>1.2.4.RELEASE</version>
    </dependency>
    <!-- If you intend to deploy the app on Cloud Foundry, add the following -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-cloudfoundry-connector</artifactId>
        <version>1.2.4.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-heroku-connector</artifactId>
        <version>1.2.4.RELEASE</version>
    </dependency>

**The manifest.yml**

---
applications:
  - name: redistomysql-consumer
    path: target/redistomysql-consumer-0.0.1-SNAPSHOT.jar
    memory: 1024M
    env:
      JAVA_OPTS: -Djava.security.egd=file:/dev/./urandom
      SPRING_PROFILES_ACTIVE: cloud
    services:
      - es-mysql-db
      - es-consumer-rabbitmq-service

buildpack: https://github.com/cloudfoundry/java-buildpack.git

env:
    JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'

org.springframework.cloud
弹簧云弹簧服务连接器
1.2.4.1发布
org.springframework.cloud
SpringCloudFoundry连接器
1.2.4.1发布
org.springframework.cloud
spring cloud heroku连接器
1.2.4.1发布
**清单.yml**
---
应用:
-名称:redistomysql使用者
路径:target/redistomysql-consumer-0.0.1-SNAPSHOT.jar
内存:1024M
环境:
JAVA_OPTS:-Djava.security.egd=file:/dev//uradom
SPRING\u配置文件\u活动:云
服务:
-es mysql数据库
-es使用者rabbitmq服务
构建包:https://github.com/cloudfoundry/java-buildpack.git
环境:
JBP_CONFIG_SPRING_AUTO_重新配置:“{enabled:false}”