简体   繁体   English

为什么`HttpClient.newHttpClient()` 不起作用?

[英]Why doesn't `HttpClient.newHttpClient()` work?

I try to learn using HTTPClient .我尝试学习使用HTTPClient But HttpClient client = HttpClient.newHttpClient();但是HttpClient client = HttpClient.newHttpClient(); does not work.不起作用。

In IntelliJ I've updated my compiler to use Java version 12 and in the pom.xml I've set java.version property to 12.IntelliJ我已将编译器更新为使用 Java 版本 12,并在pom.xml中将java.version属性设置为 12。

After I write HTTPClient it gets import sun.net.www.http.HttpClient , and then newHttpClient() method does not work.在我编写HTTPClient它会import sun.net.www.http.HttpClient ,然后newHttpClient()方法不起作用。 For this method I need import java.net.http.HttpClient;对于这种方法,我需要import java.net.http.HttpClient;

This is my pom.xml :这是我的pom.xml

<properties>
    <java.version>12</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

It works now.它现在有效。 I installed java Version 13 on my comuter and edites in Project Structure我在我的电脑上安装了 java 版本 13 并在项目结构中进行了编辑

You should add this dependency to your POM.xml您应该将此依赖项添加到 POM.xml

 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>$version</version>
 </dependency>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM