Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simplifying service lookup in the cross-store example.

  • Loading branch information...
commit 22f71da95616bf22cc55e935498544c24d2cbee8 1 parent 3d9d1da
@joshlong joshlong authored
View
16 cross-store/manifest.yml
@@ -1,18 +1,18 @@
---
applications:
- target:
- name: xs-survey
+ target/customer-survey-1.0.0-BUILD-SNAPSHOT/:
+ name: customer-survey
url: ${name}.${target-base}
framework:
- name: spring
+ name: java_web
info:
mem: 512M
- description: Java SpringSource Spring Application
+ description: Java Web Application
exec:
mem: 512M
instances: 1
services:
- survey-mongo:
- type: :mongodb
- survey-mysql:
- type: :mysql
+ mongodb-67f01:
+ type: mongodb
+ mysql-7bfaa:
+ type: mysql
View
20 cross-store/src/main/java/org/cloudfoundry/config/ServicesConfiguration.java
@@ -1,8 +1,5 @@
package org.cloudfoundry.config;
-import javax.sql.DataSource;
-
-
import org.cloudfoundry.runtime.env.CloudEnvironment;
import org.cloudfoundry.runtime.env.MongoServiceInfo;
import org.cloudfoundry.runtime.env.RdbmsServiceInfo;
@@ -28,16 +25,13 @@
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
+import javax.sql.DataSource;
+
@Configuration
@ComponentScan(basePackageClasses = CrossStoreCustomerRepository.class)
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
public class ServicesConfiguration {
-
- private String mongoDatabaseServiceName = "survey-mongo";
-
- private String mysqlDatabaseServiceName = "survey-mysql";
-
@Bean
public CloudEnvironment cloudEnvironment() {
return new CloudEnvironment();
@@ -45,7 +39,9 @@ public CloudEnvironment cloudEnvironment() {
@Bean
public MongoServiceInfo mongoServiceInfo() {
- return cloudEnvironment().getServiceInfo(mongoDatabaseServiceName, MongoServiceInfo.class);
+ MongoServiceInfo mongoServiceInfo = cloudEnvironment().getServiceInfos( MongoServiceInfo.class).iterator().next();
+ assert null != mongoServiceInfo : "there needs to be at least one MongoDB instance bound to this application" ;
+ return mongoServiceInfo;
}
@Bean
@@ -56,10 +52,10 @@ public MongoDbFactory mongoDbFactory() {
@Bean
public DataSource dataSource() {
- RdbmsServiceInfo rdbmsServiceInfo = cloudEnvironment().getServiceInfo(mysqlDatabaseServiceName, RdbmsServiceInfo.class);
+ RdbmsServiceInfo rdbmsServiceInfo = cloudEnvironment().getServiceInfos( RdbmsServiceInfo.class).iterator().next();
+ assert null != rdbmsServiceInfo : "there needs to be at least one MySQL RDBMS bound to this application";
RdbmsServiceCreator rdbmsServiceCreator = new RdbmsServiceCreator();
- DataSource dataSource = rdbmsServiceCreator.createService(rdbmsServiceInfo);
- return dataSource;
+ return rdbmsServiceCreator.createService(rdbmsServiceInfo);
}
@Bean
Please sign in to comment.
Something went wrong with that request. Please try again.