0
@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
emoleumassi
  • 4,881
  • 13
  • 67
  • 93

3 Answers3

1

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.

nogalo
  • 66
  • 8
0

In your class "SomeComponentClass", you could try putting the annotation @Autowired above your private repo, and remove it from your constructor.

@Autowired
private final SomeJpaRepository repository;

public Constructor(prop1, prop2, someMapper){
      this.property_1 = prop1;
      this.property_2 = prop2;
      this.someMapper = someMapper;
}
lvbartow
  • 41
  • 6
0

The issue is related to the order of beans creation, so it is better to create SomeJpaRepository in the context file to avoid similar issues Check this answer

Toufic
  • 292
  • 3
  • 8