'How to externalize spring repository native SQL Query to config such that queries can be changed just by having service restart

Is there a way we can externalize the entire native sql query, so that we can pull the query from config server such that the query are created at runtime rather than at compile time which would provide us with the feature to have change the query without taking a new build in cases like optimize/refactor the sql query.

Example:

Config

query:
   getuser: "SELECT * FROM User u WHERE u.id:userid"

Repository

    @Repository
    public interface UserRepository extends JpaRepository<User, Long> {
        
        @Value("${query.getuser}")
        Private String userQuery;
    
        @Query(value=userQuery,native=true)
        Public User findUserById(String userid);
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source