没有合适的资源?快使用搜索试试~ 我知道了~
spring3.0MVC注解(附实例).docx
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 66 浏览量
2022-11-18
16:00:15
上传
评论
收藏 405KB DOCX 举报
温馨提示
试读
36页
spring3.0MVC注解(附实例).docxspring3.0MVC注解(附实例).docx
资源推荐
资源详情
资源评论
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"/>
DefaultAnnotationHandlerMapping">
<property name="order">
<value>1</value>
</property>
<ref bean="sessionInterceptor"/>
<ref bean="superUserInterceptor"/>
</list>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.
AnnotationMethodHandlerAdapter">
</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
encoding="ISO-8859-1"?>
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
-->
<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
<!--
- 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>
</param-value>
<!--
<param-value>/WEB-INF/spring/applicationContext-hibernate.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-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.6 Log4jConfigListener
<!--
- 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).
-->
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
2.7 ContextLoaderListener
<!--
- 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.
-
- This means that its beans are automatically available in these child contexts,
- both for getBean(name) calls and (external) bean references.
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",
-
- 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>
<!--
- If a mapping isn't a /* subpath, the handler mappings are considered
-
- 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
剩余35页未读,继续阅读
资源评论
G11176593
- 粉丝: 6643
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功