标签:character basic 模型 apach 扫描 start value extc eth
<!-- 加载spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- springmvc前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- contextConfigLocation配置springmvc加载的配置文件(配置处理器映射器、适配器等等) 如果不配置contextConfigLocation,默认加载的是/WEB-INF/servlet名称-serlvet.xml(springmvc-servlet.xml) -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<!-- post乱码过虑器 -->
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 可以扫描controller、service、...这里让扫描controller,指定controller的包->
<context:component-scan base-package="cn.com.huiji.ssm.controller"/>
<mvc:annotation-driven/>
<!-- 视图解析器解析jsp解析,默认使用jstl标签,classpath下的得有jstl的包-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置jsp路径的前缀 -->
<property name="prefix" value="/jsp/"/>
<!-- 配置jsp路径的后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
<!-- 事务管理器 对mybatis操作数据库事务控制,spring使用jdbc的事务控制类-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源dataSource在applicationContext-dao.xml中配置了-->
<property name="dataSource" ref="dataSource"/><!-- 注意这里是ref -->
</bean>
<!-- 通知 注意这两个名称-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 传播行为 -->
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- aop事务拦截 -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* cn.com.huiji.ssm.service.impl.*.*(..))"/>
</aop:config>
<!-- 配置注解扫描 -->
<context:component-scan base-package="com.xyyz.service"/>
<!-- 加载配置文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- dbcp数据库连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- 这里的驱动name不能直接使用driver,必须是driverClassName-->
<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="maxActive" value="10" />
<property name="maxIdle" value="5" />
</bean>
<!-- c3p0连接池配置 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 这里的驱动name不能直接使用driver,必须是driverClass-->
<property name="driverClass" value="${driver_class}"/>
<!-- 数据库url -->
<property name="jdbcUrl" value="${url}"/>
<!-- 用户名-->
<property name="user" value="${username}"/>
<!-- 用户密码-->
<property name="password" value="${password}"/>
</bean>
<!-- 配置sqlsessionfatorybean -->
<bean id="sqlSessionFatory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
</bean>
<!-- 配置mapping扫描 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xyyz.mapper"/>
<!-- 这里可以不配置,扫描自己会找 -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
标签:character basic 模型 apach 扫描 start value extc eth
原文地址:http://www.cnblogs.com/xyyz/p/7261336.html