2024年5月29日发(作者:)

0.提示

1) Spring发行版本附带了PetClinic 示例,它是一个在简单的表单处理的上下文中, 利用了本节中说明

的注解支持的Web应用程序。 可以在“samples/petclinic ”目录中找到PetClinic 应用程序。

2) 另外一个建立在基于注解的Web MVC上的示例应用程序,请见imagedb 。

这个示例集中在无状态的multi-action控制器,包括多段文件上传的处理。

可以在“samples/imagedb ”目录找到imagedb 应用程序。

1.建立dispatcher实现注解支持

只有对应的HandlerMapping (为了实现类型级别的注解)和/ 或HandlerAdapter (为了实现方法

级别的注解)出现在 dispatcher中时, @RequestMapping 才会被处理。 这在DispatcherServlet 和

DispatcherPortlet 中都是缺省的行为。

然而,如果是在定义自己的HandlerMappings 或HandlerAdapters , 就需要确保一个对应的自定义

的DefaultAnnotationHandlerMapping 和 /或AnnotationMethodHandlerAdapter 同样被定义——

假设想要使用@RequestMapping 。

xmlns:xsi="/2001/XMLSchema-instance"

xsi:schemaLocation="/schema/beans

/schema/beans/">

DefaultAnnotationHandlerMapping"/>

AnnotationMethodHandlerAdapter"/>

... (controller bean definitions) ...

例1:雁联

配置DefaultAnnotationHandlerMapping 和 /或AnnotationMethodHandlerAdapter

class="tion.

DefaultAnnotationHandlerMapping">

1

AnnotationMethodHandlerAdapter">

class="nInterceptor">

class="serAccessInterceptor">

例2:

xmlns=/xml/ns/j2ee

xmlns:xsi="/2001/XMLSchema-instance"

xsi:schemaLocation="/xml/ns/j2ee

/xml/ns/j2ee/web-app_2_">

Spring PetClinic

Spring PetClinic sample application

2.1 webAppRootKey

webAppRootKey

2.3 log4jConfigLocation