0

I had follow this link: Access Spring beans from a servlet in JBoss to autowired a bean But then the properties in that Bean are null ? So what could be the problem ? Please, help me. I am new with java !!!

public class MyServlet extends HttpServlet {

  @Autowired
  private MyService myService;

  public void init(ServletConfig config) {
    super.init(config);
    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
      config.getServletContext());
  }
}
Community
  • 1
  • 1
Le Dac Sy
  • 381
  • 3
  • 16

1 Answers1

0

Spring needs a way to inject the value to your servlet. Try adding a public getter and setter:

public void getMyService() {
    return this.myService;
}

public void setMyService(MyService s) {
    this.myService = s;
}

Or a constructor that takes your MyService:

public MyServlet(MyService s) {
    this.myService = s;
}
Barett
  • 5,826
  • 6
  • 51
  • 55