Skip to content

AuditorAware and DateTimeProvider regression [DATACOUCH-647] #958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 10, 2020 · 5 comments · Fixed by #1050
Closed

AuditorAware and DateTimeProvider regression [DATACOUCH-647] #958

spring-projects-issues opened this issue Nov 10, 2020 · 5 comments · Fixed by #1050
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Eduard Dudar opened DATACOUCH-647 and commented

My application uses auditing but only for dates via @CreatedDate and @LastModifiedDate. I don't use xxxBy annotations.

With Spring Boot 2.2.x and Spring Data Couchbase 3.x, everything starts and works as expected. Even though documentation says that there must be AuditorAware<T> bean. AuditingHandler uses Optional for auditor so this requirement does not seem to be true even in 3.x version.

Now with Spring Boot 2.3 and Spring Data Couchbase 4.x, the said application does not start. First, it complains that AuditorAware bean not found. When I define one, it still complains that a bean named exactly auditorAwareRef is not found. I don't see anywhere in the documentation such naming requirement. Second, after defining auditorAwareRef, it complains that dataTimeProviderRef is missing. And similar to the auditor, a bean has to be named exactly. This part is not in the doc at all.

I feel like this is rather a regression, both beans should no be required for an application to start: the auditor is Optional and the datatimeprovider defaults to CurrentDateTimeProvider.INSTANCE


No further details from DATACOUCH-647

@spring-projects-issues
Copy link
Author

Michael Reiche commented

Hi Eduard Dudar - can you provide your application or a link to your repository?  
Thanks,

Mike

@spring-projects-issues
Copy link
Author

Eduard Dudar commented

Michael Reiche I can't provide what this ticket reported against because closed source but it fails exactly the same way on pretty much an empty, from scratch project like https://github.com/edudar/datacouch-647

@mikereiche
Copy link
Collaborator

mikereiche commented Jan 14, 2021

In the prior version where you did not get an error, the reason is that the default for the bean name was empty , and had to be explicitly set with @EnableCouchbaseAuditing(auditorAwareRef="some-name"). I will reinstate that behavior.

String auditorAwareRef() default "";

It has been change to be non-empty.

String auditorAwareRef() default "auditorAwareRef";

===============================================================

The bean annotation must have a name attribute that matches, or if it does not have a name attribute, then the method name must match.

`package app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.auditing.CurrentDateTimeProvider;
import org.springframework.data.auditing.DateTimeProvider;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing;
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
import org.springframework.data.domain.AuditorAware;

import java.util.Optional;

@SpringBootApplication
@EnableCouchbaseRepositories
@EnableCouchbaseAuditing
@EnableConfigurationProperties
public class Application {

@Bean ( name = "auditorAwareRef")
AuditorAware<?> auditorAwareRef() {
    // return new NaiveAuditorAware();
    return Optional::empty;
}

@Bean
DateTimeProvider dateTimeProviderRef() {
    return CurrentDateTimeProvider.INSTANCE;
}

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}

/**
 * This class returns a string that represents the current user
 *
 * @author Michael Reiche
 * @since 3.0
 */
 class NaiveAuditorAware implements AuditorAware<String> {

    private Optional<String> auditor = Optional.of("user1");

    @Override
    public Optional<String> getCurrentAuditor() {
        return auditor;
    }

    public void setAuditor(String auditor) {
        this.auditor = Optional.of(auditor);
    }
}

}`

@edudar
Copy link

edudar commented Jan 15, 2021

In the prior version where you did not get an error, the reason is that the default for the bean name was empty, and had to be explicitly set with @EnableCouchbaseAuditing(auditorAwareRef="")

@mikereiche That's not something I do recall. I've been using @EnableCouchbaseAuditing without explicit name references for either auditor or datetimeprovider before the migration.

@mikereiche
Copy link
Collaborator

I tried without setting the attribute in the annotation and it works as you said it did/does. I'll update my earlier comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
3 participants