spring-projects / spring-projects/spring-modulith

Support option to disable external access during CDS training

Open
#924 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Nov 13, 2024.

in: event publication registry meta: investigating type: improvement
Dominant language
Java
Stars
1.2k
Forks
222
PR merge metrics
No merged PRs in 30d

Description

The following error occurred during CDS training in an app that uses spring-modulith-starter-jdbc (1.2).
This seems to be caused by opening a connection at runtime to determine the DatabaseType.
I haven't tried it with other modules, but I would like them to support CDS builds by adding an option such as -Dspring.flyway.enabled=false that does not make an external connection during CDS training, or, in the case of JDBC, an option to specify the DatabaseType statically.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseType' defined in class path resource [org/springframework/modulith/events/jdbc/JdbcEventPublicationAutoConfiguration.class]: Failed to instantiate [org.springframework.modulith.events.jdbc.DatabaseType]: Factory method 'databaseType' threw exception with message: Unsupported database type: UNKNOWN
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda-zsh(AbstractBeanFactory.java:337)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
	at am.ik.note.NoteApiApplication.main(NoteApiApplication.java:10)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.modulith.events.jdbc.DatabaseType]: Factory method 'databaseType' threw exception with message: Unsupported database type: UNKNOWN
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
	... 19 more
Caused by: java.lang.IllegalArgumentException: Unsupported database type: UNKNOWN
	at org.springframework.modulith.events.jdbc.DatabaseType.lambda(DatabaseType.java:54)
	at java.base/java.util.Optional.orElseThrow(Unknown Source)
	at org.springframework.modulith.events.jdbc.DatabaseType.from(DatabaseType.java:54)
	at org.springframework.modulith.events.jdbc.JdbcEventPublicationAutoConfiguration.databaseType(JdbcEventPublicationAutoConfiguration.java:45)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
	... 20 more

The current workaround is to add -Dspring.autoconfigure.exclude=org.springframework.modulith.events.jdbc.JdbcEventPublicationAutoConfiguration during training.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.