SpringMVC 3.1.2的配置

本文详细介绍SpringMVC3.1.2的配置过程,包括web.xml、spring-core.xml及spring-mvc.xml的配置内容。通过具体示例展示了如何设置DispatcherServlet、数据源、事务管理等关键组件,并提供了多个DAO实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

签: Spring MVC
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://lavasoft.blog.51cto.com/62575/1043600
SpringMVC 3.1.2的配置
 
ssi的框架
 
web.xml
<? xml  version ="1.0"  encoding ="UTF-8" ?> 
< web-app  xmlns ="http://java.sun.com/xml/ns/javaee" 
                  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" 
                 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
                  version ="2.5" > 

         < servlet > 
                 < servlet-name >SpringMVC </ servlet-name > 
                 < servlet-class >org.springframework.web.servlet.DispatcherServlet </ servlet-class > 
                 < init-param > 
                         < param-name >contextConfigLocation </ param-name > 
                         < param-value >/WEB-INF/classes/spring-*.xml </ param-value > 
                 </ init-param > 
                 < load-on-startup >1 </ load-on-startup > 
         </ servlet > 
         < servlet-mapping > 
                 < servlet-name >SpringMVC </ servlet-name > 
                 < url-pattern >*.do </ url-pattern > 
         </ servlet-mapping > 
</ web-app >
 
spring-core.xml
<? xml  version ="1.0"  encoding ="UTF-8" ?> 

< beans  default-autowire ="byName" 
              xmlns ="http://www.springframework.org/schema/beans" 
              xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:aop ="http://www.springframework.org/schema/aop" 
              xmlns:context ="http://www.springframework.org/schema/context" 
              xmlns:tx ="http://www.springframework.org/schema/tx" 
             xsi:schemaLocation=" 
                        http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                        http://www.springframework.org/schema/aop 
                        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
                        http://www.springframework.org/schema/contex 
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd 
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" > 

         < bean  id ="propertyConfig"  class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > 
                 < property  name ="locations" > 
                         < list > 
                                 < value >classpath:jdbc.properties </ value > 
                         </ list > 
                 </ property > 
         </ bean > 

    < bean  id ="dataSource"  class ="org.apache.commons.dbcp.BasicDataSource"  destroy-method ="close" > 
                 < property  name ="driverClassName" > 
                         < value >${jdbc.driver} </ value > 
                 </ property > 
                 < property  name ="url" > 
                         < value >${jdbc.url} </ value > 
                 </ property > 
                 < property  name ="username" > 
                         < value >${jdbc.user} </ value > 
                 </ property > 
                 < property  name ="password" > 
                         < value >${jdbc.password} </ value > 
                 </ property > 
         </ bean > 

         < bean  id ="transactionManager" 
                     class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" > 
                 < property  name ="dataSource"  ref ="dataSource" /> 
         </ bean > 

         < bean  id ="sqlMapClient" 
                     class ="org.springframework.orm.ibatis.SqlMapClientFactoryBean" > 
                 < property  name ="configLocation"  value ="classpath:sqlMapConfig.xml" /> 
                 < property  name ="dataSource"  ref ="dataSource" /> 
         </ bean > 
    < bean  id ="mysqlDialect"  class ="com.lavasoft.freamwork.core.dialect.MySQLPhysicalSegmentDialect" /> 
         < bean  id ="sqlExecutor"  class ="com.lavasoft.freamwork.core.PhysicalSegmentSqlExecutor" > 
                 < property  name ="dialect"  ref ="mysqlDialect" /> 
         </ bean > 

         < bean  id ="baseDao"  abstract ="true"  class ="com.lavasoft.freamwork.core.dao.BaseIBatisDAO"  init-method ="initialize" > 
                 < property  name ="dataSource" > 
                         < ref  bean ="dataSource" /> 
                 </ property > 
                 < property  name ="sqlMapClient" > 
                         < ref  bean ="sqlMapClient" /> 
                 </ property > 
                 < property  name ="sqlExecutor" > 
                         < ref  bean ="sqlExecutor" /> 
                 </ property > 
         </ bean > 

         < bean  id ="bk_kindDAO"  class ="com.lavasoft.dxbk.dao.Bk_kindDAO"  parent ="baseDao" /> 
         < bean  id ="bk_taskDAO"  class ="com.lavasoft.dxbk.dao.Bk_taskDAO"  parent ="baseDao" /> 
         < bean  id ="bk_task_logDAO"  class ="com.lavasoft.dxbk.dao.Bk_task_logDAO"  parent ="baseDao" /> 
         < bean  id ="bookDAO"  class ="com.lavasoft.dxbk.dao.BookDAO"  parent ="baseDao" /> 
         < bean  id ="ebookDAO"  class ="com.lavasoft.dxbk.dao.EbookDAO"  parent ="baseDao" /> 
         < bean  id ="shopdataDAO"  class ="com.lavasoft.dxbk.dao.ShopdataDAO"  parent ="baseDao" /> 
         < bean  id ="urlregDAO"  class ="com.lavasoft.dxbk.dao.UrlregDAO"  parent ="baseDao" /> 
         < bean  id ="sec_bk_taskDAO"  class ="com.lavasoft.dxbk.dao.Sec_bk_taskDAO"  parent ="baseDao" /> 
         < bean  id ="sec_kwDAO"  class ="com.lavasoft.dxbk.dao.Sec_kwDAO"  parent ="baseDao" /> 
         < bean  id ="sec_subDAO"  class ="com.lavasoft.dxbk.dao.Sec_subDAO"  parent ="baseDao" /> 
         < bean  id ="secbookDAO"  class ="com.lavasoft.dxbk.dao.SecbookDAO"  parent ="baseDao" /> 
         < bean  id ="listfileDAO"  class ="com.lavasoft.dxbk.dao.ListfileDAO"  parent ="baseDao" /> 
         < bean  id ="str2010DAO"  class ="com.lavasoft.dxbk.dao.Str2010DAO"  parent ="baseDao" /> 
         < bean  id ="pdfdirDAO"  class ="com.lavasoft.dxbk.dao.PdfdirDAO"  parent ="baseDao" /> 

         < bean  id ="bookSV"  class ="com.lavasoft.dxbk.service.BookSVImpl" > 
                 < property  name ="bk_kindDAO"  ref ="bk_kindDAO" /> 
                 < property  name ="bookDAO"  ref ="bookDAO" /> 
         </ bean > 
</ beans >
 
spring-mvc.xml
<? xml  version ="1.0"  encoding ="UTF-8" ?> 
< beans  xmlns ="http://www.springframework.org/schema/beans" 
              xmlns:mvc ="http://www.springframework.org/schema/mvc" 
              xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:context ="http://www.springframework.org/schema/context" 
             xsi:schemaLocation=" 
                http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-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/mvc 
                http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd" > 
  < bean  class ="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" > 
                 < property  name ="messageConverters" > 
                         < list > 
                          < bean  class ="org.springframework.http.converter.ByteArrayHttpMessageConverter" /> 
                               < bean  class ="org.springframework.http.converter.StringHttpMessageConverter" > 
                                         < property  name ="supportedMediaTypes" > 
                                                 < list > 
                                                         < value >text/html; charset=utf-8 </ value > 
                                                 </ list > 
                                         </ property > 
                                 </ bean > 
                           < bean  class ="org.springframework.http.converter.ResourceHttpMessageConverter" /> 
                        < bean  class ="org.springframework.http.converter.xml.SourceHttpMessageConverter" /> 
             < bean  class ="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" /> 
         < bean  class ="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" /> 
                         </ list > 
                 </ property > 
         </ bean > 

         < mvc:annotation-driven /> 
         < context:component-scan  base-package ="com.lavasoft.dxbk.web.controller" > </ context:component-scan > 

         < mvc:resources  mapping ="/js/**"  location ="/js/" /> 
         < mvc:resources  mapping ="/css/**"  location ="/css/" /> 

         < bean  class ="org.springframework.web.servlet.view.InternalResourceViewResolver" > 
                 < property  name ="viewClass"  value ="org.springframework.web.servlet.view.JstlView" /> 
                 < property  name ="prefix"  value ="/jsp/" /> 
                 < property  name ="suffix"  value =".jsp" /> 
         </ bean > 

</ beans > 
 
spring配置文件在src下面。

本文出自 “熔 岩” 博客,请务必保留此出处http://lavasoft.blog.51cto.com/62575/1043600










本文转自yunlielai51CTO博客,原文链接:http://blog.51cto.com/4925054/1177154,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值