At present in my spring mvc based application i am implementing Servlets as well (this is a healthcheck servlet). I am trying to inject dependency of a class in this servlet using @Autowire annotation but this class is not instantiating.
Please consider the below code.
@WebServlet(name = "myServlet", urlPatterns = "/app2")
public class HealthCheckController extends HealthCheckServlet{
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
@Autowire
private MyService service;
/**
* method to check healthiness.
*
* @return true, if is healthy
* @throws HealthCheckException the health check exception
*/
@Override
public boolean isHealthy() throws HealthCheckException {
try {
service.showDetails("12", false,null);
System.out.println("True");
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
Could you please suggest how can i provide dependency of MyService class?
Thanks in advance.