Reputation: 299
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:
Controller class
Boot
Request
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>
Upvotes: -1
Views: 92
Reputation: 171
Refer this on how to structure your code, so that @SpringBootApplication reads your class annotated with @Controller class
Upvotes: 0
Reputation: 954
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.
Upvotes: 0