没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring mvc 3 注解精华.docx
资源详情
资源评论
资源推荐

0.提示
1)Spring 发行版本附带了 PetClinic示例,它是一个在简单的表单处理的上下文中,利用了本节中
说明的注解支持的 Web 应用程序。可以在“samples/petclinic”目录中找到 PetClinic应用程序。
2)另外一个建立在基于注解的 WebMVC 上的示例应用程序,请见 imagedb。
这个示例集中在无状态的 multi-action 控制器,包括多段文件上传的处理。
可以在“samples/imagedb”目录找到 imagedb应用程序。
1.建立 实现注解支持
只有对应的 HandlerMapping(为了实现类型级别的注解)和/或 HandlerAdapter(为了实
现方法级别的注解)出现在dispatcher 中时,@RequestMapping才会被处理。这在
DispatcherServlet和 DispatcherPortlet中都是缺省的行为。
然而,如果是在定义自己的 HandlerMappings或 HandlerAdapters,就需要确保一个对应
的自定义的 和/或
同样被定义——假设想要使用@RequestMapping。
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beanclass="org.springframework.web.servlet.mvc.
"/>
<beanclass="org.springframework.web.servlet.mvc.
"/>
...(controllerbeandefinitions)...
</beans>
例 :雁联
配置 DefaultAnnotationHandlerMapping和/或 AnnotationMethodHandlerAdapter
<context:component-scanbase-package="com.ylink.zfpt.web.spring"/>
<beanid="annotationHandlerMapping"class="org.springframework.web.servlet.m
vc.annotation.
DefaultAnnotationHandlerMa
pping">
<propertyname="order">
<value>1</value>
</property>
<propertyname="interceptors">

<list>
<refbean="sessionInterceptor"/>
<refbean="superUserInterceptor"/>
</list>
</property>
</bean>
<beanclass="org.springframework.web.servlet.mvc.annotation.
AnnotationMethodHandlerAd
apter">
<propertyname="webBindingInitializer">
<beanclass="com.ylink.zfpt.web.spring.ZfptBindingInitializer"/>
</property>
</bean>
<beanid="sessionInterceptor"class="com.ylink.zfpt.web.intercepor.SessionIn
terceptor">
</bean>
<beanid="superUserInterceptor"
class="com.ylink.zfpt.web.intercepor.SuperUserAccessInterceptor"></
bean>
例 :
<?xmlversion="1.0"encoding="ISO-8859-1"?>
<web-appversion="2.4"
xmlns=http://java.sun.com/xml/ns/j2eexmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-
app_2_4.xsd">
<display-name>SpringPetClinic</display-name>
<description>SpringPetClinicsampleapplication</description>
2.1 !
<!--
Keyofthesystempropertythatshouldspecifytherootdirectoryofthis
webapp.Appliedby"#or#$%&#.
-->
<context-param>
<param-name> !</param-name>
<param-value>petclinic.root</param-value>
</context-param>
2.3$%&#
<!--

LocationoftheLog4Jconfigfile,forinitializationandrefreshchecks.
AppliedbyLog4jConfigListener.
-->
<context-param>
<param-name>$%&#</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
2.4&#
<!--
-LocationoftheXMLfilethatdefinestherootapplicationcontext.
-AppliedbyContextLoaderServlet.
-
-Canbesetto:
-"/WEB-INF/applicationContext-hibernate.xml"fortheHibernateimplementati
on,
-"/WEB-INF/applicationContext-jpa.xml"fortheJPAone,or
-"/WEB-INF/applicationContext-jdbc.xml"fortheJDBCone.
-->
<context-param>
<param-name>&#</param-name>
<param-value>
/WEB-INF/spring/applicationContext-jdbc.xml
/WEB-INF/applicationContext-security.xml
</param-value>
<!--
<param-value>/WEB-INF/spring/applicationContext-hibernate.xml</param-value>
<param-value>/WEB-INF/spring/applicationContext-jpa.xml</param-value>
-->
<!--
TousetheJPAvariantabove,youwillneedtoenableSpringload-time
weavinginyourserverenvironment.Outofthebox,Springwilltryto
detecttherunningenvironmentandusetheappropriateweaverbutifthat
fails,onemustenableonebyhandorusetheVM-wideweaver.
SeePetClinic'sreadmeand/orSpring'sJPAdocumentationformoreinformatio
n.
-->
</context-param>
2.5'!(&
<filter>

<filter-name>'!(&</filter-name>
<filter-class>
org.springframework.web.filter.()!
</filter-class>
</filter>
<filter-mapping>
<filter-name>'!(&</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.6#$%&#
<!--
-ConfiguresLog4Jforthiswebapp.
-Asthiscontextspecifiesacontext-param"log4jConfigLocation",itsfile
path
-isusedtoloadtheLog4Jconfiguration,includingperiodicrefreshchecks
.
-
-WouldfallbacktodefaultLog4Jinitialization(non-refreshing)ifnospe
cial
-context-paramsaregiven.
-
-Exportsa"webapprootkey",i.e.asystempropertythatspecifiesthero
ot
-directoryofthiswebapp,forusageinlogfilepaths.
-Thiswebappspecifies"petclinic.root"(seelog4j.propertiesfile).
-->
<!--Leavethelistenercommented-outifusingJBoss-->
<listener>
<listener-class>org.springframework.web.util.#$%&#</listener-
class>
</listener>
2.7&##
<!--
-Loadstherootapplicationcontextofthiswebappatstartup,
-bydefaultfrom"/WEB-INF/applicationContext.xml".
-NotethatyouneedtofallbacktoSpring'sContextLoaderServletfor
-J2EEserversthatdonotfollowtheServlet2.4initializationorder.
-
-UseWebApplicationContextUtils.getWebApplicationContext(servletContext)
-toaccessitanywhereinthewebapplication,outsideoftheframework.

-
-Therootcontextistheparentofallservlet-specificcontexts.
-Thismeansthatitsbeansareautomaticallyavailableinthesechildconte
xts,
-bothforgetBean(name)callsand(external)beanreferences.
-->
<listener>
<listener-class>
org.springframework.web.context.&##
</listener-class>
</listener>
2.8'
<!--
-Servletthatdispatchesrequesttoregisteredhandlers(Controllerimpleme
ntations).
-Hasitsownapplicationcontext,bydefaultdefinedin"{servlet-name}-
servlet.xml",
-i.e."petclinic-servlet.xml".
-
-Awebappcancontainanynumberofsuchservlets.
-Notethatthiswebapphasasharedrootapplicationcontext,servingasp
arent
-ofallDispatcherServletcontexts.
-->
<servlet>
<servlet-name></servlet-name>
<servlet-class>
org.springframework.web.servlet.'
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!--
-Mapsthepetclinicdispatcherto"*.do".Allhandlermappingsin
-petclinic-servlet.xmlwillbydefaultbeappliedtothissubpath.
-Ifamappingisn'ta/*subpath,thehandlermappingsareconsidered
-relativetothewebapproot.
-
-NOTE:Asingledispatchercanbemappedtomultiplepaths,likeanyservle
t.
-->
<servlet-mapping>
剩余34页未读,继续阅读















munandong
- 粉丝: 2
- 资源: 15
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- ARM Cortex-A(armV7)编程手册V4.0.pdf
- ABB机器人保养总结解析.ppt
- 【超详细图解】菜鸡如何理解双向链表的python代码实现
- 常用网络命令的使用 ipconfig ping ARP FTP Netstat Route Tftp Tracert Telnet nslookup
- 基于单片机控制的DC-DC变换电路
- RS-232接口电路的ESD保护.pdf
- linux下用time(NULL)函数和localtime()获取当前时间的方法
- Openstack用户使用手册.docx
- KUKA KR 30 hA,KR 60 hA机器人产品手册.pdf
- Java programming with JNI
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0