This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to java config, later versions of Spring and Spring Data Mong…
…o and the Cloud Foundry runtime
- Loading branch information
Showing
26 changed files
with
1,634 additions
and
1,573 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
123
cross-store/src/main/java/org/cloudfoundry/config/ServicesConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
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; | ||
import org.cloudfoundry.runtime.service.document.MongoServiceCreator; | ||
import org.cloudfoundry.runtime.service.relational.RdbmsServiceCreator; | ||
import org.springframework.context.annotation.AdviceMode; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; | ||
import org.springframework.data.mongodb.MongoDbFactory; | ||
import org.springframework.data.mongodb.core.MongoExceptionTranslator; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.crossstore.MongoChangeSetPersister; | ||
import org.springframework.data.mongodb.crossstore.MongoDocumentBacking; | ||
import org.springframework.data.mongodb.examples.custsvc.data.CrossStoreCustomerRepository; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.JpaVendorAdapter; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor; | ||
import org.springframework.orm.jpa.vendor.Database; | ||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@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(); | ||
} | ||
|
||
@Bean | ||
public MongoServiceInfo mongoServiceInfo() { | ||
return cloudEnvironment().getServiceInfo(mongoDatabaseServiceName, MongoServiceInfo.class); | ||
} | ||
|
||
@Bean | ||
public MongoDbFactory mongoDbFactory() { | ||
MongoServiceCreator mongoServiceCreator = new MongoServiceCreator(); | ||
return mongoServiceCreator.createService(mongoServiceInfo()); | ||
} | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
RdbmsServiceInfo rdbmsServiceInfo = cloudEnvironment().getServiceInfo(mysqlDatabaseServiceName, RdbmsServiceInfo.class); | ||
RdbmsServiceCreator rdbmsServiceCreator = new RdbmsServiceCreator(); | ||
DataSource dataSource = rdbmsServiceCreator.createService(rdbmsServiceInfo); | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
public MongoTemplate mongoTemplate() { | ||
return new MongoTemplate(mongoDbFactory()); | ||
} | ||
|
||
@Bean | ||
public JpaVendorAdapter jpaVendorAdapter() { | ||
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); | ||
hibernateJpaVendorAdapter.setDatabase(Database.MYSQL); | ||
hibernateJpaVendorAdapter.setGenerateDdl(true); | ||
return hibernateJpaVendorAdapter; | ||
} | ||
|
||
@Bean | ||
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() { | ||
LocalContainerEntityManagerFactoryBean lcfb = new LocalContainerEntityManagerFactoryBean(); | ||
lcfb.setJpaVendorAdapter(jpaVendorAdapter()); | ||
lcfb.setDataSource(dataSource()); | ||
return lcfb; | ||
} | ||
|
||
@Bean | ||
public PlatformTransactionManager platformTransactionManager() { | ||
JpaTransactionManager txMan = new JpaTransactionManager(); | ||
txMan.setEntityManagerFactory(localContainerEntityManagerFactoryBean().getObject()); | ||
return txMan; | ||
} | ||
|
||
@Bean | ||
public MongoDocumentBacking mongoDocumentBacking() { | ||
MongoDocumentBacking mdb = MongoDocumentBacking.aspectOf(); | ||
mdb.setChangeSetPersister(changeSetPersister()); | ||
return mdb; | ||
} | ||
|
||
@Bean | ||
public MongoChangeSetPersister changeSetPersister() { | ||
MongoChangeSetPersister mongoChangeSetPersister = new MongoChangeSetPersister(); | ||
mongoChangeSetPersister.setEntityManagerFactory(localContainerEntityManagerFactoryBean().getObject()); | ||
mongoChangeSetPersister.setMongoTemplate(mongoTemplate()); | ||
return mongoChangeSetPersister; | ||
} | ||
|
||
@Bean | ||
public MongoExceptionTranslator mongoExceptionTranslator() { | ||
return new MongoExceptionTranslator(); | ||
} | ||
|
||
@Bean | ||
public PersistenceAnnotationBeanPostProcessor persistenceAnnotationBeanPostProcessor() { | ||
return new PersistenceAnnotationBeanPostProcessor(); | ||
} | ||
|
||
@Bean | ||
public PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor() { | ||
return new PersistenceExceptionTranslationPostProcessor(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
cross-store/src/main/java/org/cloudfoundry/config/WebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.cloudfoundry.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.mongodb.examples.custsvc.web.CloudFoundryEnvironmentHandlerInterceptor; | ||
import org.springframework.web.servlet.config.annotation.*; | ||
import org.springframework.web.servlet.view.InternalResourceViewResolver; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
@Import(ServicesConfiguration.class) | ||
@ComponentScan("org.springframework.data.mongodb.examples.custsvc.web") | ||
public class WebConfiguration extends WebMvcConfigurerAdapter { | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); | ||
} | ||
|
||
@Bean | ||
public CloudFoundryEnvironmentHandlerInterceptor interceptor() { | ||
return new CloudFoundryEnvironmentHandlerInterceptor(); | ||
} | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(this.interceptor()); | ||
} | ||
|
||
@Override | ||
public void addViewControllers(ViewControllerRegistry registry) { | ||
registry.addViewController("/").setViewName("index"); | ||
} | ||
|
||
@Override | ||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { | ||
configurer.enable(); | ||
} | ||
|
||
@Bean | ||
public InternalResourceViewResolver internalResourceViewResolver() { | ||
InternalResourceViewResolver ir = new InternalResourceViewResolver(); | ||
ir.setPrefix("/WEB-INF/views/"); | ||
ir.setSuffix(".jsp"); | ||
return ir; | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
cross-store/src/main/java/org/cloudfoundry/services/CloudApplicationContextInitializer.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.