2

Following is my directory structure

  1. com.example
  2. com.example.common
  3. com.example.test
  4. com.example.test.repository

my main spring boot class is as follow

package com.example.test;

@Import({ AutoConfig.class })
@SpringBootApplication
public class testApplication {
  public static void main(String[] args) {
    SpringApplication.run(testApplication.class, args);
  }
}

my repository clas

package com.example.test.repository.ConfigRepository;

 @Repository
 public interface ConfigRepository extends MongoRepository<Config, String>, QuerydslPredicateExecutor<Config> {

}

This is the error i am getting in debug mode

DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: file [/opt/<folder_name>/<folder_name>/target/classes/com/example/test/repository/ConfigRepository.class]

AutoConfig class used in @import is as below

package com.example.common;

@Configuration
@EnableFeignClients
@ComponentScan({ "com.example.common" })
public class AutoConfig {
Roshan
  • 77
  • 9

1 Answers1

1

Your ConfigRepository class in in com.example.test.repository this package.

and while providing @ComponentScan, you are passing this path com.example.common.

So instead of that you just tried with this com.example.test path as below.

And also on your SpringBootApplication file or on your Config file you can provide EnableMongoRepositories and setting basePackages attributes.

package com.example.test;

@Import({ AutoConfig.class })
@EnableMongoRepositories(basePackages = {"com.example.test.repository"})
@SpringBootApplication
public class testApplication {
  public static void main(String[] args) {
    SpringApplication.run(testApplication.class, args);
  }
}

@Configuration
@EnableFeignClients
@ComponentScan({ "com.example.test" })
public class AutoConfig {

More about @EnableMongoRepositories you will get an idea from here. This will help you.

Sagar Gangwal
  • 7,544
  • 3
  • 24
  • 38
  • but if i write com.example.test, the classes present in com.example.common will not get scanned and it contains all the configuration class which are required for me. – Roshan Sep 05 '20 at 09:28
  • it is working now but why it was not working as expected ? – Roshan Sep 05 '20 at 09:39
  • i mean it should have worked with annotation @repository right ? – Roshan Sep 05 '20 at 09:41
  • You need to inform container this is my Repository classes. Either of below option. `@EnableAutoConfiguration` for Spring Boot to figure it out itself or `@EnableMongoRepositories(basePackageScan="com.example.test.repository")` to specify it yourself https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-use-spring-data-repositories – Sagar Gangwal Sep 05 '20 at 09:43
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221005/discussion-between-roshan-and-sagar-gangwal). – Roshan Sep 05 '20 at 09:46