servlet3注解

今天再次用了下servlet3.1,我无论在类怎么写注解,发现没作用...这时找servlet3的规范了.终于找到我的问题的原因.

servlet3.1 final release:http://download.oracle.com/otndocs/jcp/servlet-3_1-fr-spec/index.html

第8章就说到注解与可插拔性.

In a web application, classes using annotations will have their annotations processed 
only if they are located in the WEB-INF/classes directory, or if they are packaged 
in a jar file located in WEB-INF/lib within the application. 

在web应用里,使用了注解的类,只有放到 WEB-INF/classes目录下或打成jar文件包放到WEB-INF/lib目录下才会处理它们的注解


.那放在其它地方就不会处理了???

1.做一下classes的windows快捷方式(这个相当于linux下的软链接),不管你成不成功,反正我没有成功!!!.不知linux成不成功,暂时没环境,不理.

2.再修改tomcat的conf/catalina.properties的shared.loader=,让tomcat加载这些类,反正是成功了!!!!


The web application deployment descriptor contains a new “metadata-complete” 
attribute on the web-app element. The “metadata-complete” attribute defines 
whether the web descriptor is complete, or whether the class files of the jar file 
should be examined for annotations and web fragments at deployment time. If 
“metadata-complete” is set to "true", the deployment tool MUST ignore any 
servlet annotations that specify deployment information present in the class files of 
the application and web fragments. If the metadata-complete attribute is not 
specified or is set to "false", the deployment tool must examine the class files of the 
application for annotations, and scan for web fragments.

web应用部署描述器(指的是web.xml)在web-app元素上包含了一个新的“metadata-complete” 属性,“metadata-complete” 属性是用来定义web描述器是不是完整的.

或者说是在部署的时候,类文件和jar文件是否要检验注解和片断(这个陌生).如果“metadata-complete” 设为"true",那部署工具一定会忽略......

如果“metadata-complete” 没有指定,或设为"false",部署工具必须检查应用的类文件注解和扫描web片断.


如果web.xml和注解都指定某个类为servlet会怎样呢,会冲突吗???狂汗.....

url-pattern不能相撞,否则tomcat死掉,启动都不让!!!!很容易理解哈....


因为我复制了tomcat examples下面的xml文件,metadata-complete也刚好是true.傻了吧.

你可能感兴趣的:(servlet3注解)