Skip to content

IllegalArgumentException in AsciiDoc generation for Spring @EventListeners without parameters #1006

Closed
@frademacher

Description

@frademacher

Hi all,

I'm currently experimenting with Spring Modulith 1.3.1 and found it to be a great initiative towards supporting the transition from Big Balls of Mud into properly structured monoliths. So first of all, thanks a lot for this :-)

However, I'm currently encountering an IllegalArgumentException when trying to generate AsciiDoc diagrams from an experimental codebase that uses a Spring @EventListener method to store initial data into an ephemeral H2 database. The method signature is as follows:

@Component
public class CatalogData {
    ...

    @EventListener(ApplicationStartedEvent.class)
    public void initialData() {
        // Invoke some save() operations in an injected repository
        ...
    }

The above code works flawlessly when running the Spring application. However, when attempting AsciiDoc generation using the following method

class ArchitectureTest {
    ...

    private static final ApplicationModules MODULES = ApplicationModules.of(App.class);
    void generateAsciiDoc() {
        var diagramOpts = Documenter.DiagramOptions.defaults().withStyle(Documenter.DiagramOptions.DiagramStyle.UML);
        var canvasOpts = Documenter.CanvasOptions.defaults();
		new Documenter(MODULES).writeDocumentation(diagramOpts, canvasOpts);
    }
}

I'm getting an IllegalArgumentException stating that

Method JavaMethod{....initialData()} must have at least one parameter!

from

The error is straightforward, and adding a parameter for the caught event and therefore changing the method signature to

    public void initialData(ApplicationStartedEvent event) {

fixes the issue.

Still wanted to report it, because Spring seemingly allows omitting the event parameter, while Spring Modulith seems to expect it.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions