I have a multiple modules Spring-boot application, I have two submodules:
- spring-boot-rest-api-todo-list
- persistence
that are organized like this:
persistence module
<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">
<parent>
<artifactId>tutorials</artifactId>
<groupId>com.medkhelifi</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>persistence</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
spring-boot-rest-api-todo-list module
<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">
<parent>
<artifactId>tutorials</artifactId>
<groupId>com.medkhelifi</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-rest-api-todo-list</artifactId>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.medkhelifi.tutorials.springboot.restapi.todolist.RestTodoListApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.medkhelifi</groupId>
<artifactId>persistence</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>spring-boot-rest-api-todo-list</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
In my rest-api module, I want to scan both modules (persistence and restapi) and I proceed like this:
@SpringBootApplication
@ComponentScan ({"com.medkhelifi.tutorials.springboot", "com.medkhelifi.tutorials.persistence"})
public class RestTodoListApplication {
@Autowired
private UserRepository userRepository;
public static void main (String[] args){
SpringApplication.run(RestTodoListApplication.class, args);
}
}
But I got this error :
Field userRepository in com.medkhelifi.tutorials.springboot.restapi.todolist.RestTodoListApplication required a bean of type 'com.medkhelifi.tutorials.persistence.model.repositories.UserRepository' that could not be found.
Action:
Consider defining a bean of type 'com.medkhelifi.tutorials.persistence.model.repositories.UserRepository' in your configuration.
If I remove "com.medkhelifi.tutorials.spring-boot"
from ComponentScan the error disappear but my controllers under my restapi module will not work.
I tried many variations of ComponentScan, but with the same error:
@ComponentScan ({"com.medkhelifi.tutorials"})
@ComponentScan ({"com.medkhelifi.tutorials.persistence", "com.medkhelifi.tutorials.springboot"})