Partage
  • Partager sur Facebook
  • Partager sur Twitter

Erreur Cours Microservice Spring

Sujet résolu
17 octobre 2018 à 14:54:13

Bonjour, je suis face à un problème assez gênant, je suis actuellement entrain de suivre le cours sur les microservice avec spring vers la fin de la page et je suis bloqué car j'ai une erreur. Le cours étant déjà très difficile à suivre car le cours est bourré d'erreur (manque d'espace dans le code, nom de variable et de fonctions erronés ) ce qui fait que je dois adapter à chaque fois pour que ça marche.

Au niveau de la création du DAO tout plante:

class Product:

package com.ecommerce.microcommerce.model;


public class Product 
{
	private int id;
	private String nom;
	private int prix;
	
	public Product() {
	}
	
	public Product(int id, String nom, int prix) {
		this.id = id;
		this.nom = nom;
		this.prix = prix;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public int getPrix() {
		return prix;
	}
	public void setPrix(int prix) {
		this.prix = prix;
	}
	
	@Override
	public String toString()
	{
		return "Product{"
				+ "id= "+
				", nom= '"+ nom + '\''+
				", prix=" + prix + '}';
	}

}

class ProductDao:

package com.ecommerce.microcommerce.dao;
import com.ecommerce.microcommerce.model.Product;
import java.util.List;

public interface ProductDao 
{
	public List<Product>findAll();
	public Product findById(int id);
	public Product save(Product product);
}

class ProductDaoImpl:

package com.ecommerce.microcommerce.dao;
import com.ecommerce.microcommerce.model.Product;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;

@Repository
public class ProductDaoImpl implements ProductDao 
{
	public static List<Product>products=new ArrayList<>();
	static 
	{
		products.add(new Product(1, new String("Ordinateur Portable"), 350));
		products.add(new Product(2, new String("Aspirateur Robot"), 250));
		products.add(new Product(3, new String("Table Ping Pong"), 500));
		
	}

	@Override
	public List<Product> findAll() {
		return products;
	}

	@Override
	public Product findById(int id) 
	{
		for (Product product : products)
		{
			if(product.getId() ==  id)
			{
				return product;
			}
		}
		return null;
		
	}

	@Override
	public Product save(Product product) 
	{
		products.add(product);
		return product;
		
	}

}

et la class ProductController où j'ai l'erreur:

package com.ecommerce.microcommerce.web.controller;
import com.ecommerce.microcommerce.dao.ProductDao;
import com.ecommerce.microcommerce.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
public class ProductController 
{
	@Autowired
	private Product productDao;
	
	//recuperer liste produits
	@GetMapping(value="/Produits")
		public List<Product>listeProduits()
		{
			return productDao.findAll();
		}
	
	//recuperer produit par id
	@GetMapping(value="/Produits/{id}")
		public Product afficherProduit(@PathVariable int id)
		{
			return productDao.findById(id);
		}

}

mes méthodes finAll et findById ne trouvent pas quelque chose et je ne sais pas quoi...

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productController': Unsatisfied dependency expressed through field 'productDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ecommerce.microcommerce.model.Product' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)
***************************
APPLICATION FAILED TO START
***************************

Description:

Field productDao in com.ecommerce.microcommerce.web.controller.ProductController required a bean of type 'com.ecommerce.microcommerce.model.Product' that could not be found.


Action:

Consider defining a bean of type 'com.ecommerce.microcommerce.model.Product' in your configuration.




Si vous pouviez m'aider et si possible revoir le cours car je si vers les débuts et il faut tout adapter et qu'on à des erreurs je n'ose pas imaginer la suite :/

Merci à vous, bonne journée.


-
Edité par SartVille 17 octobre 2018 à 15:45:40

  • Partager sur Facebook
  • Partager sur Twitter
19 juillet 2019 à 15:42:42

Le cours a été revu tu devrais y trouver ta réponse :)

-
Edité par olcariz 19 juillet 2019 à 15:47:48

  • Partager sur Facebook
  • Partager sur Twitter