使用Sqlite3的Spring Boot无法自动装配JPArepository接口

时间:2019-03-20 02:44:48

标签: java spring-boot sqlite spring-data-jpa

我正在使用最新的Spring Boot 2.1.3版本和Sqlite3作为数据库。编译没有错误,但是Spring在尝试自动装配JpaRepository bean时没有启动抛出autowire异常的原因。我到底在做什么。

这是我的pom.xml:

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.globomatics</groupId>
<artifactId>bike</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>bike</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>com.zsoltfabok</groupId>
        <artifactId>sqlite-dialect</artifactId>
        <version>1.0</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

这是我的主要课程:

package com.globomatics.bike;

    @SpringBootApplication
    public class BikeApplication {

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

    }

BikeController:

package com.globomatics.bike.controllers;

   @RestController
@RequestMapping("/api/v1/bikes")
public class BikesController {

    @Autowired
    private BikeRepository bikeRepository;


      @GetMapping public List<Bike> list(){ return bikeRepository.findAll(); }

我的实体类:

 package com.globomatics.bike.models;

@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
public class Bike {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private String name;
    private String email;
    private String phone;
    private String model;
    private String serialNumber;
    private BigDecimal purchasePrice;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM-dd-yyyy")
    private Date purchaseDate;
    private boolean contact;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getSerialNumber() {
        return serialNumber;
    }
    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }
    public BigDecimal getPurchasePrice() {
        return purchasePrice;
    }
    public void setPurchasePrice(BigDecimal purchasePrice) {
        this.purchasePrice = purchasePrice;
    }
    public Date getPurchaseDate() {
        return purchaseDate;
    }
    public void setPurchaseDate(Date purchaseDate) {
        this.purchaseDate = purchaseDate;
    }
    public boolean isContact() {
        return contact;
    }
    public void setContact(boolean contact) {
        this.contact = contact;
    }
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }


}

最后是存储库:

package com.globomatics.bike.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.globomatics.bike.models.Bike;

public interface BikeRepository extends JpaRepository<Bike, Long> {

}
  

********************************应用程序无法启动

     
     

说明:

     

野外自行车存放处   com.globomatics.bike.controllers.BikesController需要一个Bean   键入“ com.globomatics.bike.repositories.BikeRepository”无法   被发现。

     

注入点具有以下注释:     -@ org.springframework.beans.factory.annotation.Autowired(required = true)

     

操作:

     

考虑定义一个类型的bean   您的“ com.globomatics.bike.repositories.BikeRepository”   配置。

0 个答案:

没有答案