[英]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.