对l的配置:
<?xml version="1.0"encoding="UTF-8"?>
<web-app version="2.5"
xmlns="java.sun/xml/ns/javaee"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="java.sun/xml/ns/javaee java.sun/xml/ns/javaee/web-app_2_5.xsd">
<!--(第一启动)指定jdbc配置文件的位置等-->
<context-param>
<param-name>contextConfigLocation</param-name> <param-value>l</param-v alue>mvc的三层架构
</context-param>
<!--(第二启动)spring监听springmvc环境-->
<listener>
<listener-class>org.t.Contex tLoaderListener</listener-class>
</listener>
<!--(第三启动)编码springMVC内置编码-->
<filter>
<filter-name>encodingFilter</filter-name>
<!--字符串编码格式设置-->
<filter-class>org.springframework.web.filter.Character EncodingFilter</filter-class>
<!--默认编码格式为utf-8-->
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<!--在html页面或表单中设置编码是没有用的,也就是说除了utf-8设置其它格式都会被utf-8覆盖掉-->
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<!--Filter负责拦截的URL全部以/的请求,如果
<url-pattern>/*.action</>,将会以拦截*.action的请求--> <url-pattern>/*</url-pattern>
</filter-mapping>
<!--(第四启动)前置总控制器总控制器-->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.Dispatc herServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name> <param-value>l</param-value ><!--l为对应的配置文件-->
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!--缺省的servlet,即用来处理所有servlet无法处理得访问请求-->
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern><!--会对静态资源进行拦截-->
</servlet-mapping>
<!--首页-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
对l的配置:
<?xml version="1.0"encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance" xmlns:context="/schema/cont ext"
xmlns:tx="/schema/tx" xmlns:aop="/schema/aop"
xsi:schemaLocation="
/schema/beans /schema/beans/spring-bea ns-3.1.xsd
/schema/context
/schema/context/spring-cont ext-3.1.xsd
/schema/tx
/schema/tx/spring-tx-3.1. xsd
/schema/aop /schema/aop/spring-aop-3.
1.xsd"
default-lazy-init="true"><!--懒加载-->
<!--指定配置jdbc-->
<context:property-placeholder
location="classpath:jdbc.properties"/>
<!--DBCP连接池配置(hibernate不支持)-->
<bean id="dataSource"
class="org.apachemons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driver}"/>
<property name="url"value="${jdbc.url}"/>
<property name="username"value="${jdbc.username}"/>
<property name="password"value="${jdbc.password}"/>
<property name="defaultAutoCommit"value="false"/>
<!--连接池初始值-->
<property name="initialSize"value="1"/>
<!--连接池最大值-->
<property name="maxActive"value="2000"/>
<!--连接池最大空闲值-->
<property name="maxIdle"value="2"/>
<!--连接池最小空闲值-->
<property name="minIdle"value="1"/>
</bean>
<!--使用annotation自动注册bean过滤掉control-->
<context:component-scan base-package="ach"> <context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!--jdbcTemplate配置-->
<bean id="daoTemplate"class="util.JdbcDaoTemplate"> <property name="dataSource"
ref="dataSource"></property>
</bean>
<!--========================事务配置1
========================-->
<!--配置事务管理器-->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceT ransactionManager">
<property name="dataSource"
ref="dataSource"></property>
</bean>
<!--配置事务特性,配置add、delete和update开始的方法,事务传播特性为required-->
<tx:advice id="txAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*"propagation="REQUIRED"/>
<tx:method name="delete*"propagation="REQUIRED" />
<tx:method name="update*"propagation="REQUIRED" />
<tx:method name="save*"propagation="REQUIRED"/>
<tx:method name="*"propagation="NOT_SUPPORTED" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--配置事物增强方法,让该项目中所有service包中的方法拥有事物-->
<aop:config>
<aop:pointcut id="managerMethod"
expression="execution(*service.*.*(..))"/> <aop:advisor advice-ref="txAdvice"
pointcut-ref="managerMethod"/>
</aop:config>
</beans>
对jdbc.properties的配置:
jdbc.sql.jdbc.Driver
jdbc.url=jdbc:mysql:////test///代表是连接的本地数据库jdbc.username=root
jdbc.password=root
对l的配置:
<?xml version="1.0"encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance" xmlns:context="/schema/cont ext"
xmlns:p="/schema/p" xmlns:util="/schema/util"
xmlns:mvc="/schema/mvc"
xsi:schemaLocation="/sch ema/mvc
/schema/mvc/spring-mvc-3.1. xsd
/schema/beans
/schema/beans/spring-beans-3.1.xsd
/schema/util
/schema/util/spring-util-3.
1.xsd
/schema/context
/schema/context/spring-cont ext-3.1.xsd">
<!--配置js,css等静态文件直接映射到对应的文件夹,不被DispatcherServlet处理-->
<mvc:resources mapping="/resource/**"
location="/resource/"/>
<mvc:resources mapping="/upload/**"location="/upload/" />
<!--扫描所有包-->
<context:component-scan base-package="*"
use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
<!--日期转换必须放在<mvc:annotation-driven/>前面--> <bean id="conversionService"
class="org.springframework.format.support.FormattingConve rsionServiceFactoryBean">
<property name="converters">
<list>
<bean class="util.DateConverter"/>
</list>
</property>
</bean>
<mvc:annotation-driven
conversion-service="conversionService"/>
<!--文件上传配置
<bean id="multipartResolver"

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。