我试图利用标准春天的数据存储库和自定义库的。他们可能在一个问题主要的课程和我已经根据我的理解来完成所有的事情,但无法弄清楚。无法自动装配弹簧数据的自定义库在春季引导和org.springframework.data.mapping.PropertyReferenceException
封装结构:
起价ProductController.java,我的代码未能autowire.I花了几个小时,以understand.Still没有!
以下是从主类开始的.java类。
EcomApp.java
@EnableJpaRepositories("com.ecom.repo")
@EntityScan("com.ecom.model")
@ComponentScan(basePackages={"com.ecom.controller","com.ecom.model","com.ecom.service","com.ecom.repo","com.ecom.customRepo"})
@EnableAutoConfiguration
public class EcomApp {
public static void main(String[] args) throws Exception {
SpringApplication.run(EcomApp.class, args);
}
}
ProductController.java
@Controller
@RequestMapping(value="/product")
public class ProductController {
private ProductService productService;
@Autowired
public ProductController(ProductService productService) {
this.productService = productService;
}
@RequestMapping("/list")
public String productList(Model model){
model.addAttribute("product",productService.getMinimumProductDetails());
return "ecom.productList";
}
}
ProductService.java
public interface ProductService {
List<ProductDetails> getMinimumProductDetails();
}
ProductServiceImpl.java
@Service
public class ProductServiceImpl implements ProductService {
private ProductRepo productRepo;
@Autowired
public ProductServiceImpl(ProductRepo productRepo) {
super();
this.productRepo = productRepo;
}
@Override
public List<ProductDetails> getMinimumProductDetails() {
return productRepo.fetchMinimumProductDetails();
}
}
ProductRepo.java
@Repository
public interface ProductRepo extends CrudRepository<ProductDetails, Integer>,ProductCustomRepo {
}
ProductCustomRepo.java
public interface ProductCustomRepo {
List<ProductDetails> fetchMinimumProductDetails();
}
ProductCustom RepoImpl.java
public class ProductCustomRepoImpl implements ProductCustomRepo {
@PersistenceContext
private EntityManager em;
@Override
public List<ProductDetails> fetchMinimumProductDetails() {
return em.createQuery("select NEW com.ecom.model.ProductDetails(pr.productName,pr.productCategory,pr.productCondtion,pr.productPrice) from ProductDetails as pr").getResultList();
}
}
格式化差错
org.springframework.beans.factory.UnsatisfiedDependencyException:错误创建名称为豆 'ProductController的' 在文件中定义[E:\代码构建\项目\ ECOM \ target \ classes \ com \ ecom \ controller \ ProductController.class]:
通过类型为[com.ecom.service.ProductService]的索引0的构造函数参数表示的不满足依赖项:创建名称为'productServiceImpl'的bean时出错:
注入自动装配依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配方法:public void com.ecom.service.ProductServiceImpl.setProductRepo(com.ecom.repo.ProductRepo);
嵌套异常是org.springframework.beans.factory。BeanCreationException:创建名为'productRepo'的bean时出错:初始化方法的调用失败;嵌套异常是org.springframework.data.mapping.PropertyReferenceException:没有找到类型为ProductDetails的属性fetchMinimumProductDetails!
嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'productServiceImpl'的bean时出错:注入自动装配依赖失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配方法:public void com.ecom.service.ProductServiceImpl.setProductRepo(com.ecom.repo.ProductRepo);嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名为'productRepo'的bean时出错:init方法的调用失败;嵌套异常是org.springframework.data.mapping.PropertyReferenceException:没有找到类型为ProductDetails的属性fetchMinimumProductDetails!
有关完整的文本 --->https://www.dropbox.com/s/457gm8uuhvjnesi/Error.txt?dl=0
感谢兄弟。最终工作! – Prash