WebClient not resolving
Asked Answered
R

3

5

In order to utilise the new WebClient API, I've included spring-webflux in my Intellij project.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-webflux'
//    compile group: 'org.springframework', name: 'spring-webflux', version: '5.2.7.RELEASE'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

However, WebClient remains unresolved:

C:\Users\tobia\Documents\spring-app\service\Service.java:25: error: cannot find symbol
        System.out.println(WebClient.Builder());
                           ^
  symbol:   variable WebClient
  location: class Service

The dependency itself seems to have resolved, as webflux is now in my "external libraries" list:

enter image description here


Does anybody have any idea why WebClient remains unresolved?


I've tried all 4 of these dependency declerations, and none work:

    compile 'org.springframework.boot:spring-boot-starter-webflux'
    compile group: 'org.springframework', name: 'spring-webflux', version: '5.2.7.RELEASE'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation group: 'org.springframework', name: 'spring-webflux', version: '5.2.7.RELEASE'
Reseat answered 19/6, 2020 at 23:14 Comment(2)
Try the second one it works for me link.Assessment
@Assessment doesn't fix errorReseat
T
7

Your build.gradle is missing this dependency:

compile group: 'org.springframework', name: 'spring-webflux', version: '5.2.7.RELEASE'

Proof of working:

WebClient

Make sure to reimport the dependencies.

The sample code for WebClient should look like this:

        WebClient client3 = WebClient
                .builder()
                .baseUrl("http://localhost:8080")
                .defaultCookie("cookieKey", "cookieValue")
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .defaultUriVariables(Collections.singletonMap("url", "http://localhost:8080"))
                .build();

Notice that it's WebClient.builder() and not WebClient.Builder(), it looks like you have a typo in the method name, replace Builder() with builder() and it should work.

WebClient.Builder is an Interface, therefore this code is not valid:

System.out.println(WebClient.Builder());

It's a syntax issue with you code that has nothing to do with Gradle, dependencies or IntelliJ IDEA.

Tench answered 19/6, 2020 at 23:50 Comment(6)
This doesn't work, I tried it (which is why it was commented out)Reseat
Please see the updated answer showing that it works fine.Tench
I had to invalidate my caches, for some reason.Reseat
It's a syntax issue with you code that has nothing to do with Gradle, dependencies or IntelliJ IDEA.Tench
It wasn't. I didnt change any code, and after the refresh, it started resolving. Also I spelt it right. WebClient was the issue - not Builder. However, you are right in saying the builder() method is lowercase, while the class is uppercaseReseat
Can you clarify equivalent pom.xml setting ? I don't use gradleTurnaround
T
2

I had the same issue too, and I am using this dependency:

implementation 'org.springframework.boot:spring-boot-starter-webflux'

I also had to invalidate IntelliJ caches at File > Invalidate Caches

Til answered 23/2, 2023 at 18:33 Comment(1)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewTenement
T
0

In my case, I have to delete a dependency.

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webflux</artifactId>
        <scope>test</scope>
    </dependency>
Taste answered 23/8 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.