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:
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'
Your build.gradle
is missing this dependency:
compile group: 'org.springframework', name: 'spring-webflux', version: '5.2.7.RELEASE'
Proof of working:
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.