找不到房产类型

时间:2017-07-04 14:05:17

标签: spring maven postgresql-9.1

我正在处理一个项目,但是我没有找到属性类型错误。 请检查我的代码并尝试了解问题所在。

package com.bisoft.staj.poi;

import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class PoiApplication implements CommandLineRunner {

    @Autowired
    MesafeRepository mesafeRepository;

    public static void main(String[] args) {
        SpringApplication.run(PoiApplication.class, args);
    }

    @Override
    public void run(String... strings) throws Exception {
        System.out.println("Debug");

        FileInputStream file = new FileInputStream(new File("C:/Users/MONSTER/Desktop/Hello.xlsx"));
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFSheet sheet = workbook.getSheetAt(0);
        Row row;
        for (int i = 1; i <= sheet.getLastRowNum(); i++) {
            row = (Row) sheet.getRow(i);  //sheet number

            String kayitNo;
            if (row.getCell(0) == null) {
                kayitNo = "0";
            } else {
                kayitNo = row.getCell(0).toString();
            }

            int cihazNo = 0;
            if (row.getCell(1) != null) {
                cihazNo = (int) row.getCell(1).getNumericCellValue();
            }
            String plaka;
            if (row.getCell(2) == null) {
                plaka = "null";
            } else {
                plaka = row.getCell(2).toString();                           //exceldeki isimleri
            }
            String surucu;
            if (row.getCell(3) == null) {
                surucu = "null";
            } else {
                surucu = row.getCell(3).toString();
            }
            float ilkMesafeSayaci = 0;
            if (row.getCell(4) != null) {
                ilkMesafeSayaci = (float)row.getCell(4).getNumericCellValue();
            }
            String ilkMesafeTarih;
            if (row.getCell(5) == null) {
                ilkMesafeTarih = "null";
            } else {
                ilkMesafeTarih = row.getCell(5).toString();
            }
            float sonMesafeSayaci = 0;
            if (row.getCell(6) != null) {
                sonMesafeSayaci = (float)row.getCell(6).getNumericCellValue();
            }
            String sonMesafeTarih;
            if (row.getCell(7) == null) {
                sonMesafeTarih = "null";
            } else {
                sonMesafeTarih = row.getCell(7).toString();
            }
            float toplamMesafe = 0;
            if (row.getCell(8) != null) {
                toplamMesafe = (float)row.getCell(8).getNumericCellValue();
            }

            Mesafe c = new Mesafe();
            c.setCihazNo(cihazNo);
            c.setPlaka(plaka);
            c.setSurucu(surucu);
            c.setIlkMesafeSayaci(ilkMesafeSayaci);
            c.setIlkMesafeTarih(ilkMesafeTarih);
            c.setSonMesafeSayaci(sonMesafeSayaci);
            c.setSonMesafeTarih(sonMesafeTarih);
            c.setToplamMesafe(toplamMesafe);
            mesafeRepository.save(c);

            System.out.println(cihazNo + " " + plaka + " " + surucu);

        }

        mesafeRepository.findByName("Berkin").forEach(System.out::println);

        file.close();
        System.out.println("Completed!");
    }
}

存储库

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bisoft.staj.poi;

import java.io.Serializable;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;

/**
 *
 * @author MONSTER
 */
public interface MesafeRepository extends JpaRepository<Mesafe, Long>{

    public List<Mesafe> findByName(String name);
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bisoft.staj.poi;

import javax.annotation.Generated;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

/**
 *
 * @author MONSTER
 */
@Entity
public class Mesafe {

    @Id
    @SequenceGenerator(name = "customersequence", sequenceName = "customersequence", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customersequence")
    private Long kayitNo;
    private int cihazNo;
    private String plaka;
    private String surucu;
    private float ilkMesafeSayaci;
    private String ilkMesafeTarih;
    private float sonMesafeSayaci;
    private String SonMesafeTarih;
    private float toplamMesafe;

    public Long getKayitNo() {
        return kayitNo;
    }

    public void setKayitNo(Long kayitNo) {
        this.kayitNo = kayitNo;
    }

    public int getCihazNo() {
        return cihazNo;
    }

    public void setCihazNo(int cihazNo) {
        this.cihazNo = cihazNo;
    }

    public String getPlaka() {
        return plaka;
    }

    public void setPlaka(String plaka) {
        this.plaka = plaka;
    }

    public String getSurucu() {
        return surucu;
    }

    public void setSurucu(String surucu) {
        this.surucu = surucu;
    }

    public float getIlkMesafeSayaci() {
        return ilkMesafeSayaci;
    }

    public void setIlkMesafeSayaci(float ilkMesafeSayaci) {
        this.ilkMesafeSayaci = ilkMesafeSayaci;
    }

    public String getIlkMesafeTarih() {
        return ilkMesafeTarih;
    }

    public void setIlkMesafeTarih(String ilkMesafeTarih) {
        this.ilkMesafeTarih = ilkMesafeTarih;
    }

    public float getSonMesafeSayaci() {
        return sonMesafeSayaci;
    }

    public void setSonMesafeSayaci(float sonMesafeSayaci) {
        this.sonMesafeSayaci = sonMesafeSayaci;
    }

    public String getSonMesafeTarih() {
        return SonMesafeTarih;
    }

    public void setSonMesafeTarih(String SonMesafeTarih) {
        this.SonMesafeTarih = SonMesafeTarih;
    }

    public float getToplamMesafe() {
        return toplamMesafe;
    }

    public void setToplamMesafe(float toplamMesafe) {
        this.toplamMesafe = toplamMesafe;
    }

    @Override
    public String toString() {
        return "Mesafe{" + "kayitNo=" + kayitNo + ", cihazNo=" + cihazNo + ", plaka=" + plaka + ", surucu=" + surucu + ", ilkMesafeSayaci=" + ilkMesafeSayaci + ", ilkMesafeTarih=" + ilkMesafeTarih + ", sonMesafeSayaci=" + sonMesafeSayaci + ", SonMesafeTarih=" + SonMesafeTarih + ", toplamMesafe=" + toplamMesafe + '}';
    }
}

错误

by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mesafeRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property name found for type Mesafe!
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    ... 18 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Mesafe!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:89) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:64) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
    ... 28 common frames omitted

我的pom.xml和application.properties文件工作正常,问题出在哪里?感谢...

1 个答案:

答案 0 :(得分:0)

我认为问题出在你的回购中:

public interface MesafeRepository extends JpaRepository<Mesafe, Long>{

    public List<Mesafe> findByName(String name);
}

根据方法findByName,您的实体应具有属性name,但Mesafe实体中没有此类属性

您可以从repo中删除此方法,或将相应的属性添加到实体