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