像spring-data-jpa有@NotNull注释可以在spring-data-mongodb中使用它.
我试图使弹簧数据MongoDB的自动审计领域的解释在这里.下面是我的配置类
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.abc")
@EnableMongoRepositories(basePackages = "com.abc.xyz.repository")
@EnableMongoAuditing
public class ApplicationConfiguration {
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
ServerAddress serverAddress = new ServerAddress("127.0.0.1", 27017);
MongoCredential mongoCredential = MongoCredential.createCredential("user", "test", "abc123".toCharArray());
MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(mongoCredential));
return new SimpleMongoDbFactory(mongoClient, "test");
}
@Bean
public MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongoDbFactory());
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我添加@EnableMongoAuditing时,我在启动服务器时遇到以下错误.
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoAuditingHandler': Cannot create inner bean '(inner bean)#6dca0c34' of type [org.springframework.data.mongodb.config.MongoAuditingRegistrar$MongoMappingContextLookup] while setting …Run Code Online (Sandbox Code Playgroud)