I created a Filter and definitely it will be called every request. I have this database call: dbService.getNeeded()
. How can I make this call once only and use it in the entire calling of filter?
public class MyFilter extends OncePerRequestFilter {
@Autowired
private DBService dbService;
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
boolean isNeeded = dbService.getNeeded();
if (isNeeded) {
// do something
}
}
}