@CreatedBy @LastModifiedBy annotations are not working

Add below annotation to your Application Class.

@EnableJpaAuditing(auditorAwareRef = "auditorAware")

Define the bean:

@Bean
public AuditorAware<String> auditorAware(){
    return new CustomAuditAware();
}

Create CustomAuditAware class:

public class CustomAuditAware implements AuditorAware<String> {

    @Override
    public String getCurrentAuditor() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    if (authentication == null || !authentication.isAuthenticated()) {
        return null;
    }

    return ((User) authentication.getPrincipal()).getUsername();
}

https://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-auditing-part-two/