简体   繁体   English

如何在 spring-boot 应用程序中为 @Query(value=xyz) 提供最终值

[英]How to provide final value for @Query(value=xyz) in spring-boot application

I am reading my SQL queries from property file and the same I am passing to @Query(value=xyz) but getting consistent error "Attribute value must be constant".我正在从属性文件中读取我的 SQL 查询,并且我正在传递给 @Query(value=xyz) 但得到一致的错误“属性值必须是恒定的”。 Is there any solution available for this?有没有可用的解决方案?

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");
}

I am trying to use it in blow code.我正在尝试在打击代码中使用它。

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


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

Try making your String findAllTags2 a final field尝试使您的 String findAllTags2 成为最终字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Spring-Boot CrudRepository 中获取数组中具有值的对象列表 - How to get List of Objects with value in array in Spring-Boot CrudRepository 缺失值 Spring-Boot RestController - Missing value Spring-Boot RestController 如何使用 Swing 应用程序配置 spring-boot - How to configure spring-boot with swing application 如何将spring-boot作为客户端应用程序运行? - How to run spring-boot as a client application? 如何在Spring Boot中为通用类提供类类型? - How to provide the classtype for generic classes in spring-boot? 使用动态值覆盖 Junit 测试中的默认 Spring-Boot application.properties 设置 - Override default Spring-Boot application.properties settings in Junit Test with dynamic value 将值设置/放入Spring-boot的Spring环境中以供以后使用 - Set/Put value into Spring environment of Spring-boot for using later 如何在spring-boot 1.4.3中覆盖spring-boot应用程序属性 - How to override spring-boot application properties in spring-boot 1.4.3 如何在 spring 引导中将参数值传递给查询? - how to pass parameter value into query in spring boot? Spring-boot:将默认值设置为可配置属性 - Spring-boot: set default value to configurable properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM