Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try making your String findAllTags2 a final field


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...