Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何修复创建名为';springProductAppApplication';:通过字段'表示未满足的依赖关系;productrepo';;_Java_Spring_Spring Boot_Hibernate_Spring Mvc - Fatal编程技术网

Java 如何修复创建名为';springProductAppApplication';:通过字段'表示未满足的依赖关系;productrepo';;

Java 如何修复创建名为';springProductAppApplication';:通过字段'表示未满足的依赖关系;productrepo';;,java,spring,spring-boot,hibernate,spring-mvc,Java,Spring,Spring Boot,Hibernate,Spring Mvc,尝试:org.springframework.beans.factory.UnsatifiedDependencyException:创建名为“springProductAppApplication”的bean时出错:通过字段“productrepo”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“productRepository”的bean时出错:调用init方法失败;嵌套异常为jav

尝试:org.springframework.beans.factory.UnsatifiedDependencyException:创建名为“springProductAppApplication”的bean时出错:通过字段“productrepo”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“productRepository”的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:未能为方法public abstract com.product.demo.model.product com.product.demo.dao.ProductRepository.findAllById(长)创建查询!未找到产品类型的属性id

attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProductAppApplication': Unsatisfied dependency expressed through field 'productrepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.product.demo.model.Product com.product.demo.dao.ProductRepository.findAllById(long)! No property id found for type Product!




 ****Service class****

package com.product.demo.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.product.demo.dao.ProductRepository;
import com.product.demo.model.Product;

@Service
public class ProductService {
    
    
    @Autowired
ProductRepository productrepo;




public Product save (Product product) {
    
    return productrepo.save(product);
}


public Iterable<Product> getall(){
    return productrepo.findAll();
}


public Product findById(long productid) {
    return productrepo.findAllById(productid);
}

public List<Product> gettproduct(){
    return productrepo.findAll();
}

public void delete(Product product) {
    productrepo.delete(product);
    
}
}
**Repository class**




package com.product.demo.dao;

import java.util.List;

import org.springframework.data.repository.CrudRepository;

import com.product.demo.model.Product;


public interface ProductRepository extends CrudRepository<Product, Long> {
    
    
    @Override
    public List<Product> findAll();

    public Product findAllById(long productid);

}
**SpringProductAppApplication**

package com.product.demo;

import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


import com.product.demo.dao.ProductRepository;
import com.product.demo.services.ProductService;



@SpringBootApplication
public class SpringProductAppApplication {
    
    @Autowired
    ProductRepository productrepo;
    
    
    @Autowired
    ProductService productservice;


    public static void main(String[] args) {
        SpringApplication.run(SpringProductAppApplication.class, args);
    }
    

}

尝试将方法
findAllById
更改为有效的
findById
!非常感谢你。
**Model class Product.java**

package com.product.demo.model;




import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long  productid;
    
    private String productName;
    
    private double productPrice;

    public long getProductid() {
        return productid;
    }

    public void setProductid(int productid) {
        this.productid = productid;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public double getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(double productPrice) {
        this.productPrice = productPrice;
    }

    public Product(String productName, double productPrice) {
        super();
        this.productName = productName;
        this.productPrice = productPrice;
    }
    
    public Product() {
        
    }
    
    
    
    
    
}