我正在尝试使用spring-boot-JPA-repositories实现CRUD操作。坚持' @Autowire'概念

时间:2017-08-31 07:35:59

标签: spring-boot spring-data-jpa

我的控制器:

@RestController
@RequestMapping("/patientC")
public class PatientController {
    final static Logger logger= Logger.getLogger(PatientController.class);

    @Autowired
    PatientService patientS;

    @RequestMapping(method=RequestMethod.POST)
    public ResponseEntity<Patient> registerPatient(@RequestBody Patient p){
        patientS.saveP(p);
        logger.debug("Added::"+p);
        return new ResponseEntity<Patient> (p,HttpStatus.CREATED);
    }

PatientService Class

package com.patient.service;

import java.io.Serializable;
import java.util.List;

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

import com.patient.model.Patient;
import com.patient.repository.PatientRepository;

@Service
public class PatientService implements CRUDService<Patient> {
    @Autowired
    PatientRepository PatientR;

    public PatientService() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
    public Patient saveP(Patient entity) {      
        return PatientR.save(entity);
    }

PatientRespository类

@Repository
public interface PatientRepository extends JpaRepository<Patient, Integer> {

}

错误我通过&#39; spring-boot执行程序:运行&#39;

Field PatientR in com.patient.service.PatientService required a bean of type 'com.patient.repository.PatientRepository' that could not be found.

Caused by: Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'patientController': Unsatisfied dependency expressed through field 'patientS'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'patientService': Unsatisfied dependency expressed through field 'PatientR'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [com.patient.repository.PatientRepository]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

我是否正在使用&#39; Autowired annotation&#39;不正确?为了成功执行我的程序,我应该做些什么改变?

0 个答案:

没有答案