-1

For a long time, I am struggling to find a solution. I am trying to build a spring boot multi-module project.

I have two modules for practice purposes, later I will add more modules in my real project.

Module 1 whose name is application is where I have implemented my Controller.

Module 2 (boot) is the runner for the whole project. Both of them are inherited from the parent.

I got stuck, when I start the application, and i make a request to the end-point of the Controller. It seems that, Spring doesn't recognize it.

Project structure:

enter image description here

Controller class

enter image description here

Boot

enter image description here

Request

enter image description here

boot pom.xml

<?xml version="1.0" encoding="UTF-8"?>

4.0.0

<parent>
    <groupId>org.onebox</groupId>
    <artifactId>onebox</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>boot</artifactId>

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

application pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.onebox</groupId>
        <artifactId>onebox</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>application</artifactId>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

Parent pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.onebox</groupId>
    <artifactId>onebox</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>boot</module>
        <module>application</module>
    </modules>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.5</version>
    </parent>

    <!--<dependencies>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.7.0</version>
        </dependency>
    </dependencies>-->

</project>
2
  • Obviously, boot will have to include application as a dependency. Also, limit your classpath scanning by providing additional parameters to the @SpringBootApplication annotation. Commented Feb 23, 2024 at 12:38
  • @NicoVanBelle Could you provide an example, please? Commented Feb 23, 2024 at 14:00

2 Answers 2

0

Let's start with your Controller class being in a default package which is

a) a no-no by itself;
b) won't be scanned by your @SpringBootApplication in com.example package.

Sign up to request clarification or add additional context in comments.

Comments

0

Refer this on how to structure your code, so that @SpringBootApplication reads your class annotated with @Controller class

https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/html/using-boot-structuring-your-code.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.