Replace a context-param element with a Servlet 3.0 annotation

后端 未结 4 693
粉色の甜心
粉色の甜心 2020-12-15 09:46

Given: a Java EE 5 web app that has a web.xml that has a snippet like


    c
    

        
4条回答
  •  旧巷少年郎
    2020-12-15 10:32

    Well I think we just can't hardcode context-param using "Annotation" because there is a logical reason behind this : i am sure you guys knows annotations is always hardcoded in the Servlet and Servlet never loaded by the container in the memory for serving the client request until its first request is made by client (read Servlet Life Cycle ).

    So what happen if we want to get the values out of "context-param" , which is hard-coded using Annotation in some other Servlet ? And the Servlet wrapped with context-param annotation is still not loaded in the memory thus we can't get the object for context :)

    I think now you guys can easily guess why we can't use Annotation in case of context-param because we need to hardcode that Annotation with any specific servlet and we can't do that .......

提交回复
热议问题