2017-07-04 72 views
0

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

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文件正在确定这样的问题,即可以吗?谢谢...

回答

0

我认为这个问题是在你的回购:

public interface MesafeRepository extends JpaRepository<Mesafe, Long>{ 

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

根据方法findByName,你的实体应该有一个属性name,但目前还没有这样的属性在Mesafe实体

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

+0

我怎样才能改变它?我试图用另一个班级成员替换姓名,但它不起作用 – ILLIDAN

+0

让我们来考虑一下ex'private String plaka;'。你能否尝试将方法'findByName'改为'findByPlaka'? – Leffchik