没有合适的资源?快使用搜索试试~ 我知道了~
不错的springMVC注解说明文档,可以很方便的使用与开发和解析
资源推荐
资源详情
资源评论
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 。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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">
<bean class="org.springframework.web.servlet.mvc.
DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.
AnnotationMethodHandlerAdapter"/>
... (controller bean definitions) ...
</beans>
例 1:雁联 zfpt-servlet.xml
配置 DefaultAnnotationHandlerMapping 和 /或 AnnotationMethodHandlerAdapter
<context:component-scan base-package="com.ylink.zfpt.web.spring"/>
<bean id="annotationHandlerMapping"
class="org.springframework.web.servlet.mvc.annotation.
DefaultAnnotationHandlerMapping">
<property name="order">
<value>1</value>
</property>
<property name="interceptors">
<list>
<ref bean="sessionInterceptor"/>
<ref bean="superUserInterceptor"/>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.
AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.ylink.zfpt.web.spring.ZfptBindingInitializer"/>
</property>
</bean>
<bean id="sessionInterceptor"
class="com.ylink.zfpt.web.intercepor.SessionInterceptor">
</bean>
<bean id="superUserInterceptor"
class="com.ylink.zfpt.web.intercepor.SuperUserAccessInterceptor"></bean>
例 2:web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4"
xmlns=http://java.sun.com/xml/ns/j2ee
xmlns: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>Spring PetClinic</display-name>
<description>Spring PetClinic sample application</description>
2.1 webAppRootKey
<!--
Key of the system property that should specify the root directory of this
web app. Applied by WebAppRootListener or Log4jConfigListener.
-->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>petclinic.root</param-value>
</context-param>
2.3 log4jConfigLocation
<!--
Location of the Log4J config file, for initialization and refresh checks.
Applied by Log4jConfigListener.
-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
2.4 contextConfigLocation
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderServlet.
-
- Can be set to:
- "/WEB-INF/applicationContext-hibernate.xml" for the Hibernate
implementation,
- "/WEB-INF/applicationContext-jpa.xml" for the JPA one, or
- "/WEB-INF/applicationContext-jdbc.xml" for the JDBC one.
-->
<context-param>
<param-name>contextConfigLocation</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>
-->
<!--
To use the JPA variant above, you will need to enable Spring load-time
weaving in your server environment. Out of the box, Spring will try to
detect the running environment and use the appropriate weaver but if that
fails, one must enable one by hand or use the VM-wide weaver.
See PetClinic's readme and/or Spring's JPA documentation for more
information.
-->
</context-param>
2.5 springSecurityFilterChain
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.6 Log4jConfigListener
<!--
- Configures Log4J for this web app.
- As this context specifies a context-param "log4jConfigLocation", its file
path
- is used to load the Log4J configuration, including periodic refresh checks.
-
- Would fall back to default Log4J initialization (non-refreshing) if no
special
- context-params are given.
-
- Exports a "web app root key", i.e. a system property that specifies the root
- directory of this web app, for usage in log file paths.
- This web app specifies "petclinic.root" (see log4j.properties file).
-->
<!-- Leave the listener commented-out if using JBoss -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-
class>
</listener>
2.7 ContextLoaderListener
<!--
- Loads the root application context of this web app at startup,
- by default from "/WEB-INF/applicationContext.xml".
- Note that you need to fall back to Spring's ContextLoaderServlet for
- J2EE servers that do not follow the Servlet 2.4 initialization order.
-
- Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
- to access it anywhere in the web application, outside of the framework.
-
- The root context is the parent of all servlet-specific contexts.
- This means that its beans are automatically available in these child
contexts,
- both for getBean(name) calls and (external) bean references.
-->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
2.8 DispatcherServlet
<!--
- Servlet that dispatches request to registered handlers (Controller
implementations).
- Has its own application context, by default defined in "{servlet-name}-
servlet.xml",
- i.e. "petclinic-servlet.xml".
-
- A web app can contain any number of such servlets.
- Note that this web app has a shared root application context, serving as parent
- of all DispatcherServlet contexts.
-->
<servlet>
<servlet-name>petclinic</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!--
- Maps the petclinic dispatcher to "*.do". All handler mappings in
- petclinic-servlet.xml will by default be applied to this subpath.
- If a mapping isn't a /* subpath, the handler mappings are considered
- relative to the web app root.
-
- NOTE: A single dispatcher can be mapped to multiple paths, like any servlet.
-->
<servlet-mapping>
<servlet-name>petclinic</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
2.9 exception.java
<error-page>
<exception-type>java.lang.Exception</exception-type>
剩余35页未读,继续阅读
资源评论
黄骁
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功