首页 > 解决方案 > 如何在 spring-boot 应用程序中为 @Query(value=xyz) 提供最终值

问题描述

我正在从属性文件中读取我的 SQL 查询,并且我正在传递给 @Query(value=xyz) 但得到一致的错误“属性值必须是常量”。有没有可用的解决方案?

public class QueryUtils {

    public static Properties properties;

    static {
        try {
            FileReader reader = new FileReader("sql.properties");
            properties = new Properties();
            properties.load(reader);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static  String findAllTags2 = properties.getProperty("ResourceTagRepository.find_all_tags");
}

我正在尝试在打击代码中使用它。

@Component
@Repository
public interface QueryRepo extends JpaRepository<XYZ, Long>, JpaSpecificationExecutor<XYZ> {


    @Query(value = findAllTags2)
    public List<ResourceTagMapping> findAllTags(@Param("list") Set<String> names);
}

标签: javasqlspringspring-boothibernate

解决方案


尝试使您的 String findAllTags2 成为最终字段


推荐阅读