繁体   English   中英

Java Spring异常:未找到类型xxx的属性xxx

[英]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;
        }

}

我已经尝试过重命名类,但是没有任何帮助。 没有新添加方法的旧版本可以正常工作,没有任何问题。 感谢您的帮助。

参见http://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/repositories.html#repositories.create-instances

您需要在单独的界面中定义自定义方法。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM