0

I'm working in a project that target is built a maven multi-module with quarkus. RestEasy provides an interface ExceptionMapper that intercept every exception thrown of type . My impl is contained into a maven submodule packaged in a jar file. The jar file is imported in main project, but the bean is not registered in CDI context

I have tried to force the bean registration, but is not working, the only solution that i have found was do that in main project but i think is not good

@Provider
public class FlowItemExceptionErrorHandler extends FlowItemExceptionErrorMapper {

My parent project pom structure.


  <groupId>com.dummyproject</groupId>
    <artifactId>inter-quarkus-framework-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <surefire-plugin.version>2.22.0</surefire-plugin.version>
        <quarkus.version>0.19.1</quarkus.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
        <spring.context.version>4.3.7.RELEASE</spring.context.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-bom</artifactId>
                <version>${quarkus.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.dummyproject</groupId>
                <artifactId>inter-workflow-module</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
            <dependency>
                <groupId>com.dummyproject</groupId>
                <artifactId>inter-logging-module</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-resteasy</artifactId>
            </dependency>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-arc</artifactId>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-junit5</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.context.version}</version>
            </dependency>
            <dependency>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-spring-di</artifactId>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.context.version}</version>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-spring-di</artifactId>
            <version>${quarkus.version}</version>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
            <version>${quarkus.version}</version>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
            <version>${quarkus.version}</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${surefire-plugin.version}</version>
                    <configuration>
                        <systemProperties>
                            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        </systemProperties>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>io.quarkus</groupId>
                    <artifactId>quarkus-maven-plugin</artifactId>
                    <version>${quarkus.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.quarkus</groupId>
                        <artifactId>quarkus-maven-plugin</artifactId>
                        <version>${quarkus.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                                <configuration>
                                    <enableHttpUrlHandler>true</enableHttpUrlHandler>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemProperties>
                                        <native.image.path>
                                            ${project.build.directory}/${project.build.finalName}-runner
                                        </native.image.path>
                                    </systemProperties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <modules>
        <module>inter-workflow-module</module>
        <module>inter-logging-module</module>
    </modules>

My logging module pom structure

<parent>
        <groupId>com.dummyproject</groupId>
        <artifactId>inter-quarkus-framework-parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>inter-logging-module</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>com.dummyproject</groupId>
            <artifactId>inter-workflow-module</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

My ExceptionMapper impl in logging module


@Provider
public class FlowItemExceptionErrorMapper implements ExceptionMapper<FlowItemException> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public Response toResponse(FlowItemException exception) {

        InterExceptionMetadata exceptionMetadata = exception.getClass().getAnnotation(InterExceptionMetadata.class);

        String message = null;
        int statusCode = 500;


        if (exceptionMetadata != null) {

            message = exception.getMessage();
            statusCode = exceptionMetadata.httpStatus();

            if (exceptionMetadata.defaultMessageTemplate()) {

                message = "Sistema indisponível no momento";

            }

            switch (exceptionMetadata.logLevel()) {
                case OFF:
                    break;
                case WARN:
                    logger.warn(message, exception);
                    break;
                case INFO:
                    logger.info(message, exception);
                    break;
                case DEBUG:
                    logger.debug(message, exception);
                    break;
                case TRACE:
                    logger.trace(message, exception);
                    break;
                default:
                    logger.error(message, exception);
                    break;
            }

        }

        return Response.status(statusCode).entity(message).build();

    }

}

The bean above is not registered in main project

1 Answers1

1

Quarkus does not automatically scan the additional jars. By default, it only takes into account the application classes.

Thus, if you want other dependencies (either external or in a multi-module project), you have to include them in the Jandex index.

I gave a comprehensive answer here: How to create a Jandex index in Quarkus for classes in a external module .

Guillaume Smet
  • 9,921
  • 22
  • 29