Partage
  • Partager sur Facebook
  • Partager sur Twitter

Probleme execution dans le Cours Spring Data JPA

    2 décembre 2023 à 12:23:27

    Bonjour

    Je suis entrain de suivre ce cours sur Spring Data JPA : https://openclassrooms.com/fr/courses/6982461-utilisez-spring-data-pour-interagir-avec-vos-bases-de-donnees/7201190-implementez-la-lecture-de-donnees-read

    Mais j'ai des erreurs à l'execution du code fourni dans le cours: j'obtiens cette erreur à l'exécution

    ***************************

    APPLICATION FAILED TO START

    ***************************

    Description:
    
    Field productService in com.edgconsulting.controller.ProjetAssurancesApplication required a bean of type 'com.edgconsulting.service.ProductService' that could not be found.
    
    The injection point has the following annotations:
    
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
    
    Action:
    
    Consider defining a bean of type 'com.edgconsulting.service.ProductService' in your configuration.
    

    ========

    Voici le contenu du code ce la Classe ProjetAssurancesApplication

    package com.edgconsulting.controller;
    
    import org.springframework.beans.factory.annotation.Autowired;
    
    import org.springframework.beans.factory.annotation.Qualifier;
    
    import org.springframework.boot.CommandLineRunner;
    
    import org.springframework.boot.SpringApplication;
    
    import com.edgconsulting.model.Product;
    
    import com.edgconsulting.service.ProductService;
    
    public class ProjetAssurancesApplication implements CommandLineRunner {
    
    @Autowired
    
    private ProductService productService;
    
    public static void main(String[] args) {
    
    SpringApplication.run(ProjetAssurancesApplication.class, args);
    
    }
    
    @Override
    
    public void run(String...args) throws Exception {
    
    Iterable <Product> products=productService.getProducts();
    
    products.forEach(product->System.out.println(product.getName()));
    
    }
    
    }


    =====Voici le code de la Classe ProductService:

    package com.edgconsulting.service;
    
    import org.springframework.beans.factory.annotation.Autowired;
    
    import org.springframework.stereotype.Service;
    
    import com.edgconsulting.repository.ProductRepository;
    
    @Service
    
    public class ProductService {
    
    @Autowired
    
    private ProductRepository productRepository;
    
    public Iterable <Product> getProducts() {
    
    return productRepository.findAll();
    
    }
    
    }



    -
    Edité par BASOH FOTSING MARC ANICET 2 décembre 2023 à 12:34:01

    • Partager sur Facebook
    • Partager sur Twitter

    Probleme execution dans le Cours Spring Data JPA

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    • Editeur
    • Markdown