I have a spring boot project with the following code:
import org.springframework.web.context.request.NativeWebRequest;
import javax.servlet.http.HttpServletResponse
foo(NativeWebRequest req){
HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class);
res.setCharacterEncoding("UTF-8");
}
And everything worked fine until I added velocity dependencies:
compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
compile group: 'org.apache.velocity', name: 'velocity-tools', version: '2.0'
Now I get:
In Eclipse: The method setCharacterEncoding(String) is undefined for the type HttpServletResponse
And in gradle bootJar
:
.../SomeFile.java:12: error: cannot find symbol
res.setCharacterEncoding("UTF-8");
^
symbol: method setCharacterEncoding(String)
location: variable res of type HttpServletResponse
So I figure that the version of the library that imports HttpServletResponse is somehow impacted by those dependencies.
my spring boot plugin is: id 'org.springframework.boot' version '2.3.2.RELEASE'
All dependencies in the same project are:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
// https://mvnrepository.com/artifact/org.apache.velocity/velocity
compile group: 'org.apache.velocity', name: 'velocity', version: '1.7'
// https://mvnrepository.com/artifact/org.apache.velocity/velocity-tools
compile group: 'org.apache.velocity', name: 'velocity-tools', version: '2.0'
}
From gradle dependencies
I can see that velocity sets javax.servlet:servlet-api:2.3
but without the velocity dependencies javax.servlet
doesn't appear in gradle dependencies at all, so I don't know what the version was before.
From commenting out I could determine that implementation 'org.springframework.boot:spring-boot-starter-web'
provides javax.servlet if velocity is not a dependency. (per gradle dependencies
Version 2.3.2 in compileClasspath
and (n)
in implementation
)
I also tried gradle dependencyInsight --configuration compile --dependency javax.servlet:servlet-api
without velocity, but got No dependencies matching given input were found in configuration 'compile'
.
I think these questions come very close, but I'm still unsure how to proceed in gradle:
setCharacterEncoding problems
Apache Velocity + Servlet 3.0