Can't Autowire ServletContext

后端 未结 3 1517
夕颜
夕颜 2020-12-20 11:50

I\'m new with Spring, and I\'m trying to use the @Autowire annotation for the ServletContext with my class attribute:

@Controller
public class ServicesImpl i         


        
3条回答
  •  礼貌的吻别
    2020-12-20 12:37

    Implement the ServletContextAware interface and Spring will inject it for you

    @Controller
    public class ServicesImpl implements Services, ServletContextAware{
    
    
    private ServletContext context;
    
    public void setServletContext(ServletContext servletContext) {
         this.context = servletContext;
    }
    

提交回复
热议问题