【问题标题】:how to fix UnsatisfiedDependencyException in spring framework When used @Query使用@Query时如何修复Spring框架中的UnsatisfiedDependencyException
【发布时间】:2020-02-20 22:14:09
【问题描述】:

我已经使用 springboot 创建了 WEB 服务,我使用了 JpaRepository 的简单方法,例如 .findAll() 并且一切正常。 当我尝试使用@Request - SQL 请求的 JPQL 时,出现了问题。

我尝试了一个简单的请求 @Query("SELECT content FROM qcm.tabledeteste t where t.id = ?1")

这是一个简单的例子,但我的真正目标是更新数据

在 DAO 中 ...

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface TesterDao extends  JpaRepository<Tester, String> { 
    @Query("SELECT content FROM autosv.tester t where t.id = ?1")
    String  testerQuery(String id); 
}

在控制器名称中:TesterController ....

TesterDao tDao;
@GetMapping(value = "/testerQuery")
    public String  testerQuery() {
        String t = tDao.testerQuery("7");       
        return t;
}

...

 org.springframework.beans.factory.UnsatisfiedDependencyException: Error
 creating bean with name 'TesterController': Unsatisfied dependency expressed
 through field 'tDao'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean
 with name 'TesterDao': Invocation of init method failed; nested exception is
 java.lang.IllegalArgumentException: Validation failed for query for method 

public abstract java.lang.String 

com.example.qcm.qcm.dao.TabledetesteDao.getTabledetestQuery(java.lang.String)


!

......

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: is not mapped

【问题讨论】:

    标签: sql hibernate spring-boot jpa jpql


    【解决方案1】:

    在查询中使用类名 Tester 而不是 autosv.tester。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-01
      • 2020-08-27
      • 2019-09-30
      • 2020-05-25
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 2020-10-19
      相关资源
      最近更新 更多