4

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'
Tobi Akinyemi
  • 804
  • 1
  • 8
  • 24

2 Answers2

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
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

Levan
  • 616
  • 6
  • 10
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33910478) – Datta Diware Feb 28 '23 at 03:15