Spring Data Mongo DB Audit tables are not being created

by Saurabh Kumar   Last Updated March 03, 2017 21:26 PM

My mongo DB configuration. I am not using JPA. I dont see any AUDIT table being created. Is there something i am missing.

@Configuration
@EnableMongoRepositories(basePackages = Constants.DATA_SCAN)
@EnableMongoAuditing(auditorAwareRef = "auditorAwareService")
@Import(value = {MongoAutoConfiguration.class})
public class MongoDatabaseConfiguration {

    @Bean
    public ValidatingMongoEventListener validatingMongoEventListener() {
        return new ValidatingMongoEventListener(validator());
    }

    @Bean
    public LocalValidatorFactoryBean validator() {
        return new LocalValidatorFactoryBean();
    }

    @Bean
    @Primary
    public CustomConversions customConversions() {
        final List<Converter<?, ?>> converters = new ArrayList<>();
        converters.add(JSRConverters.DateToZonedDateTimeConverter.INSTANCE);
        converters.add(JSRConverters.ZonedDateTimeToDateConverter.INSTANCE);
        return new CustomConversions(converters);
    }
}

POM

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
        <version>1.5.1.RELEASE</version>
    </dependency>

auditor aware impl

@Service("auditorAwareService")
public class AuditorAwareService implements AuditorAware<String> {

    @Override
    public String getCurrentAuditor() {
        final String userName = SecurityUtils.getCurrentUserLogin();
        return userName != null ? userName : Constants.SYSTEM_ACCOUNT;
    }
}

Model

@Document(collection = "persistent_audit_event")
public class PersistentAuditEvent implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Field("event_id")
    private String id;

    @NotNull
    private String principal;

    @Field("event_date")
    private LocalDateTime auditEventDate;

    @Field("event_type")
    private String auditEventType;

    private Map<String, String> data = new HashMap<>();
}


Related Questions


Spring boot - Issue in invoking Shutdownhook

Updated August 12, 2018 09:26 AM


Spring Boot Health Check - SQS Consumer

Updated May 11, 2018 03:26 AM