代码之家  ›  专栏  ›  技术社区  ›  Michael

如何访问中的变量应用程序属性文件

  •  -1
  • Michael  · 技术社区  · 4 年前

    三联信息: 套房: https://www.data.com/

    我需要在函数中使用suiterlin:

     public String getTridelSuites() throws IOException, InterruptedException {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .GET()
                .uri(URI.create(suiteUrl))//here
                .build();
    
    
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        return response.body();
    }
    

    我的问题是如何从java函数中获取suiteUrl值?

    1 回复  |  直到 4 年前
        1
  •  -1
  •   Md Kawser Habib    4 年前

    春季有一些选项可供选择。你可以用任何一个。

    @Autowired
    private Environment env;
    ...
    
    public String getTridelSuites() throws IOException, InterruptedException {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .GET()
                .uri(URI.create(env.getProperty("suiteUrl");))//here
                .build();
    
    
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        return response.body();
    }