Reputation: 8118
My project structure is as follows:
java/com.company.foo/container/configuration/
This folder contains
@ComponentScan({"com.company.foo.module.project",
"com.company.foo.module.user"})
@Configuration
@EnableScheduling
@Import(value = {
SecurityConfiguration.class})
public class ApplicationContextConfiguration {
}
My ResourcePlannerApplication is in this folder:
java/com.company.foo/container/
and has following annotations:
@Import({ApplicationContextConfiguration.class})
@SpringBootApplication
Now I have two modules project and user with both the same structure:
java/com.company.foo/module/user/dao/
This folder contains:
public interface UserRepository extends JpaRepository<UserEntity, Long> {
UserEntity findByUsername(String username);
}
now when I start the app it tells me:
Consider defining a bean of type 'com.company.foo.module.user.dao.UserRepository' in your configuration.
I'm not seeing the problem because the ComponentScan is scanning all the folders?
Upvotes: 2
Views: 6450
Reputation: 639
Plog's answer is correct. I just want to add that, similar solution is applicable for Mongo Repositories as well (where we have interface as a repository). Suppose, repository package is:
package com.example.respository;
Enable mongo repositories in spring application code, like below:
@EnableMongoRepositories("com.example.repsoitory")
Upvotes: 0
Reputation: 9622
JPA repositories are not picked up by component scans since they are just interfaces whos concrete classes are created dynamically as beans by Spring Data provided you have included the @EnableJpaRepositories annotation in your configuration:
@ComponentScan({"com.company.foo.module.project",
"com.company.foo.module.user"})
@Configuration
@EnableScheduling
@EnableJpaRepositories("com.company.foo.module.user")
@Import(value = {
SecurityConfiguration.class})
public class ApplicationContextConfiguration {
}
Upvotes: 4