<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-service-broker</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
@RefreshScope
@ConfigurationProperties("vcap.services.my-mysql.credentials")
public class MySqlConfig {
private String jdbcUrl;
private String username;
private String password;
// 省略 getter 和 setter 方法
}
@Autowired
private MySqlConfig mysqlConfig;
@Bean
public DataSource dataSource() {
return DataSourceBuilder.create()
.url(mysqlConfig.getJdbcUrl())
.username(mysqlConfig.getUsername())
.password(mysqlConfig.getPassword())
.build();
}
spring:
cloud:
cloudfoundry:
enabled: true
api-host: https://api.run.pivotal.io
username: your-cloudfoundry-username
password: your-cloudfoundry-password
organization: your-cloudfoundry-organization
space: your-cloudfoundry-space