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

问题描述 投票:0回答:1

我尝试使用HTTPClient学习。但是HttpClient client = HttpClient.newHttpClient();不起作用。

IntelliJ中,我已更新编译器以使用Java版本12,在pom.xml中,我已将java.version属性设置为12。

我写了HTTPClient后得到import sun.net.www.http.HttpClient,然后newHttpClient()方法不起作用。对于这种方法,我需要import java.net.http.HttpClient;

这是我的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>
java httpclient
1个回答
-2
投票

您应该将此依赖项添加到您的POM.xml中

 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>$version</version>
 </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.