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

Native Build Fails When Couchbase Auditing is Enabled #1884

Closed
korkutkose opened this issue Dec 25, 2023 · 7 comments · Fixed by #1908
Closed

Native Build Fails When Couchbase Auditing is Enabled #1884

korkutkose opened this issue Dec 25, 2023 · 7 comments · Fixed by #1908
Assignees
Labels
type: task A general task

Comments

@korkutkose
Copy link

korkutkose commented Dec 25, 2023

Hi,
On latest spring-boot version, when applied Couchbase auditing according to this article and tried build a native image image generation's failed with below trace.
When we commented out @EnableCouchbaseAuditing in the configuration class and proceeded with image generation image's been successfully built without any exceptions.
Is there any more configuration for native build generation that we should follow for auditing support?

2023-12-25T09:52:38.887+03:00  INFO 3602 --- [tams-slot-planner] [           main] [                                                 ] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10 ms. Found 2 JPA repository interfaces.
Exception in thread "main" java.lang.IllegalStateException: No constructor or factory method candidate found for Root bean: class [org.springframework.data.couchbase.core.mapping.event.AuditingEventListener]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null and argument types [org.springframework.beans.factory.ObjectFactory<java.lang.Object>]
	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorOrFactoryMethod(ConstructorResolver.java:994)
	at org.springframework.beans.factory.support.RegisteredBean.resolveConstructorOrFactoryMethod(RegisteredBean.java:212)
	at org.springframework.util.function.SingletonSupplier.get(SingletonSupplier.java:106)
	at org.springframework.beans.factory.aot.DefaultBeanRegistrationCodeFragments.getTarget(DefaultBeanRegistrationCodeFragments.java:80)
	at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:85)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$generateRegisterBeanDefinitionsMethod$2(BeanRegistrationsAotContribution.java:90)
	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.generateRegisterBeanDefinitionsMethod(BeanRegistrationsAotContribution.java:88)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$applyTo$1(BeanRegistrationsAotContribution.java:73)
	at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
	at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
	at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
	at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.applyTo(BeanRegistrationsAotContribution.java:72)
	at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
	at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
	at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
	at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
	at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
	at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
	at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
	at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
	at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:80)
@Slf4j
@Configuration
@EnableCouchbaseRepositories(basePackages = "com.acme.nosql")
@EnableCouchbaseAuditing(auditorAwareRef = "auditorAware")
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
 ...other attributes
  @Bean
  public NativeAuditorAware auditorAware() {
    return new NativeAuditorAware();
  }
}
public class NativeAuditorAware implements AuditorAware<String> {

  @Override
  public Optional<String> getCurrentAuditor() {
    String user = ContextHolder.get() != null ? ContextHolder.get().getUser() : null;
    if (StringUtils.isNotEmpty(user)) {
      return Optional.of(user);
    }
    return Optional.of("unknown");
  }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 25, 2023
@mikereiche
Copy link
Collaborator

It should work. We build and test auditing in the integration tests. Can you attach your build dependencies file - pom.xml, build.gradle, whatever.

@korkutkose
Copy link
Author

korkutkose commented Dec 28, 2023

Hey, sorry for the delay @mikereiche.
I'll do better. Here's the minimal replicator project for the issue.
korkutkose/couchbase-demo

@mikereiche
Copy link
Collaborator

mikereiche commented Jan 1, 2024

Thanks. I can reproduce it. I'll investigate.

Edit: The indicate error disappears when a constructor with the signature indicated is added to AuditEventListener

	public AuditingEventListener(ObjectFactory<Object> auditingHandlerFactory) {
		Assert.notNull(auditingHandlerFactory, "IsNewAwareAuditingHandler must not be null!");
		this.auditingHandlerFactory = (ObjectFactory<Object>) auditingHandlerFactory;
	}

Note to self: The following error occurs when running 3.2.1 spring boot with 5.3.0-SNAPSHOT spring-data-couchbase. Using the correct (5.2.1) spring data couchbase the error does not occurr.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project couchbase-demo: Compilation failure
[ERROR] Bad service configuration file, or exception thrown while constructing Processor object: com/querydsl/apt/AbstractQuerydslProcessor

@cabbonizio
Copy link

I just upgraded to Spring Boot 3.2.3 and first time I am seeing this error. I have not seen this error prior to this version of spring boot

@cabbonizio
Copy link

cabbonizio commented Feb 22, 2024

I am thinking had something to do with this commit and something with Spring Boot 3.2.3 aren't playing nice together perhaps

86713c5

@mikereiche
Copy link
Collaborator

mikereiche commented Feb 22, 2024

@cabbonizio - according to my note above, adding a constructor to AuditingEvenListener solves the issue. Not sure why I haven't done that yet.

@cabbonizio
Copy link

Ok, got it now I just saw your commit. Thanks for the response. For now, I may upgrade to Spring Boot 3.2.3 but downgrade SDC to 5.2.2 for now.

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

Successfully merging a pull request may close this issue.

4 participants