小编Meh*_*suf的帖子

Spring数据mongoDb不是像Spring数据Jpa那样的空注释

像spring-data-jpa有@NotNull注释可以在spring-data-mongodb中使用它.

spring-data-jpa spring-data-mongodb

10
推荐指数
1
解决办法
5121
查看次数

使用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)

java spring mongodb spring-data-mongodb spring-boot

6
推荐指数
2
解决办法
8031
查看次数