Search code examples
javaspring-bootjavabeans

Parameter 0 of constructor in ComponentClass required a bean of type 'JpaRepository' that could not be found


@Repository
public interface SomeJpaRepository extends JpaRepository<SomeEntity, String>
{
   @Modifying
  //....
}

my component:

@Component
@Slf4j
public class SomeComponentClass
{
   private final SomeJpaRepository repository;
   private final SomeMapper someMapper;
   private final int property_1;
   private final int property_2;

   public SapRequestQueue(SomeJpaRepository somejpaRepository, SomeMapper someMapper,
                          @Value("${xxx.property_1}") int property_1, @Value("${xxx.property_2}") int property_2)
   {
      this.property_1 = property_1;
      this.property_2 = property_2;
      this.someMapper = someMapper;
      this.somejpaRepository = somejpaRepository;
   }

My error:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023.04.28 10:01:02.622 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter:40 - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in path.service.SomeComponentClass required a bean of type 'path.service.repository.SomeJpaRepository' that could not be found.


Action:

Consider defining a bean of type 'path.service.repository.SomeJpaRepository ' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:61815', transport: 'socket'

Process finished with exit code 1

My code structure Module:

  • src
  • main
  • java
  • path.toserviceSomeComponentClass
  • path.toservice.repository.SomeJpaRepository

Solution

  • Maybe you can try adding

    @EnableJpaRepositories(basePackages = "path.toservice.repository")
    

    to the configuration. If that solves your problem, then probably something is wrong with your packages structure.