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>
サーブレットのソース...
@WebServlet(urlPatterns = { "/service/*" })
public class RequestServlet extends HttpServlet {
{
System.out.println("RequestServlet is initialized");
}
...
}
必要な動作である - 注釈付きサーブレットが初期化されます要求を待ち受けます。
実際には何も起こりません。サーブレットに注釈が付けられていないようなものです。
追加情報 - サーブレットへのパスはコンポーネントスキャンにあり、他のDI機能も有効です。
私はエンタープライズコンテナを持っていません。今まで働いていたSpring+Embeded Jettyのためにこのチュートリアルを使いました。
EDIT:以前のバージョンのJetty(7.0.2)を使用していたようです。桟橋は、コメントを1として、バージョン8
"私は使用できません"と正確にはどういう意味ですか?代わりに正確に何が起こるのですか? – BalusC
@BalusCそうです、私は質問を編集します。 – fiction
ええと、私は春をしないので、 'AbstractServlet'が正しいかどうかは分かりませんが、これは普通のServlet API(通常は' HttpServlet'です)です。しかし、Tomcat 7やGlassfish 3などのServlet 3.0互換コンテナを実行していますか? – BalusC