SpringMVC3.05+MyIbatis3.23 所需要的jar:
SpringMvc:
------------------------------------------------------------------------- myIbatis:
-------------------------------------------------------------------------- 依赖包:
本项目采用Spring3.1Mvc+MyIbatis3.24+c3p0
在一个完整的项目中,配置文件显得十分重要,如果没有配置好服务器不但可能启动不了,而且对以后的维护会产生很大的影响,因此本人将配置过程进行全部的展示;
一、项目文件的配置
l启动log4j、springmvc、spring
<?xml version="1.0"encoding="UTF-8"?>
<web-app xmlns:xsi="/2001/XMLSchema-instance"
xmlns="java.sun/xml/ns/javaee"
xmlns:web="java.sun/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="java.sun/xml/ns/javaee
java.sun/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"version="2.5">
<display-name>mi</display-name>
<!-- welcome-file-list -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 日志的配置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/properties/log4j.properties</param-value> </context-param>
param name
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-c lass>
</listener>
<!-- spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/l,classpath:config/spring /l</param-value>
</context-param>
<listener>
<listener-class>org.t.ContextLoaderListener</liste ner-class>
</listener>
<!-- SpringMVC启动 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param>
<description>spring MVC 配置文件</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/spring/l</param-value> </init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2.配置SpringMvc
<?xml version="1.0"encoding="UTF-8"?>
<beans
xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:p="/schema/p"
xmlns:context="/schema/context"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-3.0.xsd
/schema/context
/schema/context/spring-context-3.0.xsd">
<!-- .对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.sry"/>
<!-- .启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAda pter"/>
<!-- .对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"p:suffix=".jsp"/>
<!-- 支持上传文件 -->
<bean id="multipartResolver"
class="org.springframework.web.multipartmons.CommonsMultipartResolver"> <property name="maxUploadSize">
<value>1048576</value>
</property>
</bean>
<!-- SpringMVC在超出上传文件限制时,会抛出
org.springframework.web.multipart.MaxUploadSizeExceededException --> <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings">
<props>
<!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到
/WEB-INF/jsp/error_fileupload.jsp页面 -->
<prop
key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fil eupload</prop>
</props>
</property>
</bean>
</beans>
3.l配置数据库连接池、myibatis
<!-- 数据库连接池配置 -->
<bean id="dataSource"class="hange.v2.c3p0.ComboPooledDataSource"> <property
name="driverClass"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></ property>
<property
name="jdbcUrl"><value>jdbc:sqlserver://localhost:1433;databaseName=testone</valu e></property>
<property name="user"><value>sa</value></property>
<property name="password"><value>000000</value></property>
<property name="minPoolSize"><value>1</value></property>
<property name="maxPoolSize"><value>20</value></property>
<property name="maxIdleTime"><value>1800</value></property>
<property name="acquireIncrement"><value>2</value></property>
<property name="maxStatements"><value>0</value></property>
<property name="initialPoolSize"><value>2</value></property>
<property
name="idleConnectionTestPeriod"><value>1800</value></property>
<property name="acquireRetryAttempts"><value>30</value></property>
<property
name="breakAfterAcquireFailure"><value>true</value></property>
<property
name="testConnectionOnCheckout"><value>false</value></property>
</bean>
<!-- mybatis配置文件 -->
<bean id="sqlSessionFactory"
class="batis.spring.SqlSessionFactoryBean">
<property name="dataSource"ref="dataSource"/>
<!-- 自动扫描entity目录,省略l里手工配置 -->
<property name="mapperLocations"value="classpath:com/sry/mapping/*.xml"/> </bean>
<bean class="batis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage"value="com.sry.daoservices"/>
<property name="sqlSessionFactoryBeanName"value="sqlSessionFactory"/> </bean>
4.l配置事物:
<?xml version="1.0"encoding="UTF-8"?>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论