Skip to content
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

Allow overriding DateTimeProvider via Bean Definition #3177

Open
ZIRAKrezovic opened this issue Oct 15, 2024 · 1 comment
Open

Allow overriding DateTimeProvider via Bean Definition #3177

ZIRAKrezovic opened this issue Oct 15, 2024 · 1 comment
Labels
type: enhancement A general enhancement

Comments

@ZIRAKrezovic
Copy link

The default DateTimeProvider is set to CurrentDateTimeProvider.INSTANCE which returns LocalDateTime.now().

We have to override it when using OffsetDateTime as JPA will throw an error.

According to https://docs.spring.io/spring-data/jpa/reference/auditing.html#jpa.auditing.configuration it is already possible to override AuditorAware by simply defining a bean.

However, the same is not true for DateTimeProvider. I have tried defining a bean of type DateTimeProvider, but it was not picked up. I was only able to specify it via @EnableJpaAuditing(dateTimeProviderRef = "...")

(note, I used EnableJpaAuditing, but AuditingHandlerSupport is part of spring-data-commons)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 15, 2024
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 16, 2024
@mp911de
Copy link
Member

mp911de commented Oct 16, 2024

AuditingBeanDefinitionRegistrarSupport enables autowire by type if auditorAwareRef isn't set. I think we should be able to generally set autowrite mode to AUTOWIRE_BY_TYPE and back off from setting dateTimeProvider to CurrentDateTimeProvider.INSTANCE if no reference is configured as AuditingHandlerSupport initializes itself with CurrentDateTimeProvider.INSTANCE.

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

No branches or pull requests

3 participants