1
我的設置在我的本地工作,但不是在我將其部署到CloudFoundry/mongolab時。@EnableMongoAuditing MongoDB on Cloud Foundry/mongolab
該配置與docs非常相似。
我的地方Spring配置
@Configuration
@Profile("dev")
@EnableMongoAuditing
@EnableMongoRepositories(basePackages = "com.foo.model")
public class SpringMongoConfiguration extends AbstractMongoConfiguration {
@Override
protected String getDatabaseName() {
return "myDb";
}
@Override
public Mongo mongo() throws Exception {
return new MongoClient("localhost");
}
@Bean
public AuditorAware<User> myAuditorProvider() {
return new SpringSecurityAuditorAware();
}
}
這是Cloud Foundry的設置
@Configuration
@Profile("cloud")
@EnableMongoAuditing
@EnableMongoRepositories(basePackages = "com.foo.model")
public class SpringCloudMongoDBConfiguration extends AbstractMongoConfiguration {
private Cloud getCloud() {
CloudFactory cloudFactory = new CloudFactory();
return cloudFactory.getCloud();
}
@Bean
public MongoDbFactory mongoDbFactory() {
Cloud cloud = getCloud();
MongoServiceInfo serviceInfo = (MongoServiceInfo) cloud.getServiceInfo(cloud.getCloudProperties().getProperty("cloud.services.mongo.id"));
String serviceID = serviceInfo.getId();
return cloud.getServiceConnector(serviceID, MongoDbFactory.class, null);
}
@Override
protected String getDatabaseName() {
Cloud cloud = getCloud();
return cloud.getCloudProperties().getProperty("cloud.services.mongo.id");
}
@Override
public Mongo mongo() throws Exception {
Cloud cloud = getCloud();
return new MongoClient(cloud.getCloudProperties().getProperty("cloud.services.mongo.connection.host"));
}
@Bean
public MongoTemplate mongoTemplate() {
return new MongoTemplate(mongoDbFactory());
}
@Bean
public AuditorAware<User> myAuditorProvider() {
return new SpringSecurityAuditorAware();
}
}
,當我嘗試將文檔保存在Cloud Foundry中,我得到的錯誤是:
OUT ERROR: org.springframework.data.support.IsNewStrategyFactorySupport - Unexpected error
OUT java.lang.IllegalArgumentException: Unsupported entity com.foo.model.project.Project! Could not determine IsNewStrategy.
OUT at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:739)
OUT at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
OUT at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
任何想法?它是我的配置文件等..? 預先感謝 尼克拉斯
謝謝奧利弗。當我通過AbstractMongoConfiguration類時,我一定錯過了(或誤解)。我將配置文件移到了根目錄下,它可以在本地和開發中使用。乾杯! – Niclas