没有在类'org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean'中定义的带有1个参数的构造函数

时间:2018-05-02 20:05:10

标签: java spring spring-data-jpa

我第一次尝试使用JPA,而且我正在努力解决这个错误。这是我的主要课程。我所有的其他课程都在分组中。

using (var db = new MainContext())
{
    // disconnected record
    var account = new Account()
    {
        Id = accountId,
        AccountNumber = "9876",
        Customer = new Customer() {Id = customerId}
    };

    db.Entry(account).State = EntityState.Modified; // <-- enough

    db.SaveChanges();
}

这是我的存储库

@SpringBootApplication
@ImportResource({"classpath*:/META-INF/**/spring-bootstrap.xml"})
@EnableJpaRepositories
public class Application { .... }

我的职业是

 @Repository
public interface JobRepository extends JpaRepository<Job, Long>{

}

但是当我运行它时,我得到错误,创建名为'jobRepository'的bean:无法解析匹配的构造函数(提示:为简单参数指定索引/类型/名称参数以避免类型歧义)

由于JobRepository应该由Spring提供(我的理解)我在这里有点迷失并且会感激任何帮助

以下是我认为的相关依赖

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name="whatever")
public class Job implements Comparable<Job>, Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

这是完整的堆栈跟踪

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>${spring.boot.version}</version>
        <exclusions>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.0.0.Final</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.10.Final-atlassian-2</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>c3p0</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.1.2</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0.2206.100</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>1.13.3.RELEASE</version>
    </dependency>

0 个答案:

没有答案