[英]Spring Data Custom Method Error : org.springframework.data.mapping.PropertyReferenceException: No property xxx found for type
[英]Java Spring exception: No property xxx found for type class xxx
我想添加一個新的存儲庫方法,以檢索元素列表。
主要問題是:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insulinGTService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private xxx.xxx.xxx.repository.InsulinGTRepository xxx.xxx.xxx.service.jpa.InsulinGTServiceImpl.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insulinGTRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No property storelistfromcontainer found for type class xxx.xxx.xxx.domain.InsulinGT
我有點解決了,它無法自動連接InsulinGTServiceImpl中的存儲庫 ,如果您遵循此錯誤,則最終會出現在InsulinGTRepository中 ,並看到錯誤。
胰島素GTServiceImpl
@Service("insulinGTService")
@Repository
@Transactional
public class InsulinGTServiceImpl implements InsulinGTService {
@Autowired
private InsulinGTRepository repository;
@Override
@Transactional(readOnly = true)
public List<InsulinGT> findByID(Long insulinid) {
// TODO Auto-generated method stub
return Lists.newArrayList(repository.findByUserid(insulinid));
}
@Override
public InsulinGT save(InsulinGT insulin) {
return repository.save(insulin);
}
@Override
public List<InsulinGT> liststorelistfromcontainerSave(InsulinlistGT insulin) {
// TODO Auto-generated method stub
return repository.storelistfromcontainer(insulin);
}
}
胰島素GT服務
public interface InsulinGTService {
public List<InsulinGT> findByID(Long insulinid);
public InsulinGT save(InsulinGT insulin);
public List<InsulinGT> storelistfromcontainerSave(InsulinlistGT insulin);
}
在InsulinGTRepository春天說, 無效的派生查詢! 找不到InsulinGT類型的來自容器的屬性storelist!
public interface InsulinGTRepository extends CrudRepository<InsulinGT, Long> {
public List<InsulinGT> findByUserid (Long id);
public List<InsulinGT> storelistfromcontainer(InsulinlistGT insulin);
}
胰島素GT
@Entity
@Table(name = "insulin")
public class InsulinGT implements Serializable {
private static final long serialVersionUID = 3333976984277807655L;
private Long insulinid;
private Long userid;
private String ivalue;
private String therapie;
private String insulinname;
private String einheit;
private Date date;
private Date time;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "insulin_id")
public Long getInsulinid() {
return insulinid;
}
public void setInsulinid(Long insulinid) {
this.insulinid = insulinid;
}
@Column(name = "users_id")
public Long getUserid() {
return userid;
}
public void setUserid(Long userid) {
this.userid = userid;
}
@NotNull
@Column(name = "ivalue")
public String getIvalue() {
return ivalue;
}
public void setIvalue(String ivalue) {
this.ivalue = ivalue;
}
@Column(name = "date")
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@Column(name = "time")
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
@Column (name = "therapie")
public String getTherapie() {
return therapie;
}
public void setTherapie(String therapie) {
this.therapie = therapie;
}
@Column(name = "insulinname")
public String getInsulinname() {
return insulinname;
}
public void setInsulinname(String insulinname) {
this.insulinname = insulinname;
}
@Column(name = "einheit" )
public String getEinheit() {
return einheit;
}
public void setEinheit(String einheit) {
this.einheit = einheit;
}
}
我已經嘗試過重命名類,但是沒有任何幫助。 沒有新添加方法的舊版本可以正常工作,沒有任何問題。 感謝您的幫助。
您需要在單獨的界面中定義自定義方法。
public interface CustomRepo {
public List<InsulinGT> storelistfromcontainer(InsulinlistGT insulin);
}
現在定義一個基本接口
public interface InsulinGTRepository extends CrudRepository<InsulinGT, Long>, CustomRepo {
public List<InsulinGT> findByUserid (Long id);
}
還提供一個滿足CustomRepo的bean:
public class CustomRepoImpl implements CustomRepo {
@Override
public List<InsulinGT> storelistfromcontainer(InsulinlistGT insulin) {
throw new UnsupportedOperation("TODO");
}
}
注意,CustomRepoImpl的名稱很重要( extension
接口的默認bean查找策略是在Impl
后綴。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.