gpt4 book ai didi

java - spring data jpa应用使用vcap服务使用pivotal cloud foundry rabbitmq和mysql服务

转载 作者:行者123 更新时间:2023-11-29 02:13:54 24 4
gpt4 key购买 nike

我能够使用关键的 RABBITMQ 和 MYSQLSERVICES。在绑定(bind)服务时,我能够获取凭据并在我的 application.properties 中使用该凭据用于 spring data jpa 项目。

但是我正在使用的这个配置是在 application.Properties 中硬编码的。为了动态地进行这个配置,我开始知道我们可以使用 pivotal 提供的 vcap 服务。

所以想为 rabbimq 和 mysql 使用运行时凭证。

我的代码在下面供引用。

文件:application.propeties

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> {

}

如有任何帮助,我们将不胜感激。

最佳答案

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}'

关于java - spring data jpa应用使用vcap服务使用pivotal cloud foundry rabbitmq和mysql服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44126536/

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