Implementing RESTFul API in Jersey + Spring Framework, I needed the following information.
I checked the method, so I wrote it down.
Tools etc. | Version etc. |
---|---|
MacbookPro | macOS Mojave 10.14.5 |
IntelliJ IDEA | Ultimate 2019.3.3 |
Java | AdoptOpenJDK 11 |
apache maven | 3.6.3 |
Jersey | 2.30.1 |
JUnit | 5.6.0 |
Tomcat | apache-tomcat-8.5.51 |
Postman | 7.19.1 |
Spring Framework | 5.2.4-RELEASE |
Just declare it in a member variable with @Context
.
@Service
@Path("/my")
class MyResourceApi{
@Context
HttpServletRequest httpServletRequest;
@Context
HttpServletResponse httpServletResponse;
}
It seems that all other context-related information can be obtained in the same way.
This seems to be due to the annotation-based DI function HK2 that Jersey has built in from version 2 rather than the function of Jersey itself.
For more details, here.
HK2 https://javaee.github.io/hk2/introduction.html
Try the DI function (HK2) built into Jersey2 https://qiita.com/opengl-8080/items/9bdc98aa5269512bd70e
Recommended Posts