在recent Spring 3.1 Release中有一個@WebServlet
註釋支持。但似乎我無法使用它。有沒有一些教程。這是我的web.xmlSpring 3.1和Servlet API 3.0。如何使用@WebServlet註釋
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0" >
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
...和我的beans.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="xxx.xxxxxxxx.xxx" />
<!-- aop:aspectj-autoproxy aspectj-weaving="on"/-->
<bean
class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
<!-- bean class="xxx.xxxx.xxx.xxx.MessageProfileLogger"
/-->
</beans>
servlet源...
@WebServlet(urlPatterns = { "/service/*" })
public class RequestServlet extends HttpServlet {
{
System.out.println("RequestServlet is initialized");
}
...
}
所需的行爲方式 - 註釋的servlet被初始化並開始傾聽請求。
究竟發生了什麼 - 沒有什麼,它就像Servlet沒有註釋。
附加信息 - servlet的路徑在組件掃描中,其他DI的東西也適用。
我沒有企業容器,我用這個教程爲Spring+Embeded Jetty直到現在。
編輯:似乎我使用老版本的Jetty(7.0.2)。看來,碼頭支持@WebServlet 3.0版本以來8.
你對「我無法使用」有什麼意思?究竟發生了什麼? – BalusC 2011-12-16 14:25:15