我想添加一个新的存储库方法,以检索元素列表。
主要问题是:
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 你可以看到的错误。
InsulinGTServiceImpl
@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);
}
}
InsulinGTService
public interface InsulinGTService {
public List<InsulinGT> findByID(Long insulinid);
public InsulinGT save(InsulinGT insulin);
public List<InsulinGT> storelistfromcontainerSave(InsulinlistGT insulin);
}
在 InsulinGTRepository 中说,无效的派生查询!找不到类型为InsulinGT的物业storelistfromcontainer!
public interface InsulinGTRepository extends CrudRepository<InsulinGT, Long> {
public List<InsulinGT> findByUserid (Long id);
public List<InsulinGT> storelistfromcontainer(InsulinlistGT insulin);
}
InsulinGT
@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;
}
}
我alredy尝试重命名这些课程,但没有任何帮助。没有新添加方法的旧版本正常工作没有任何问题。 感谢每一位帮助。
答案 0 :(得分:0)
您需要在单独的界面中定义自定义方法。
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
为后缀。