----------------------SpringMVC需要配置的有:
1.组件扫描 <context:component-scan base-package=" "/>
2.配置mvc注册驱动<mvc:annotation-driven/>
3.开发静态资源访问权限<mvc:default-servlet-handler/>
----------------------Mybatis需要配置的有:
//在spring中配置
1.加载properties文件 properties resource是文件名jdbc.properties
2.别名 typeAliases type是类com.itheima.domain.Account alias是别名 account
或者
package name是com.itheima.domain
//在spring中配置
3.环境 environments transactionManager是JDBC dataSource type是POOLED
4.加载映射
mappers
mapper resource "com/itheima/mapper/AccountMapper.xml"
或者
package name="com.itheima.mapper"
-----------------------Spring需要配置的有:
1.组件扫描:扫描service和mapper层 并排除controller
<context:component-scan base-package="com.itheima">
<context:exclude-filter type="annotation" expression="org.springfarmework.stereotype.Controller">
</context:component-scan>
2.加载jdbc.properties
<context:property-placeholder location="jdbc.properties"></context:property-placeholder>
3.配置数据源
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="driverClass" value="${jdbc.driver}"/>
<property name="driverClass" value="${jdbc.driver}"/>
</bean>
<!--配置sessionFactroy-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--加载mybatis核心文件-->
<property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
</bean>
<!--扫描mapper所在的包 为mapper创建实现类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.itheima.mapper"/>
</bean>
-----------------------web.xml需要配置的有:
1.spring监听器
告诉web.xml spring配置文件在哪
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:appcationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.前端控制器
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup> //服务器打开就启动
<init-param> //告诉web.xml springmvc配置文件在哪
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3.乱码过滤器
<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>
-------------------------mybatis整合spring实现
1.将session工厂交给spring容器管理,从容器中获得执行操作的Mapper实例即可
<!--配置sessionFactroy-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--加载mybatis核心文件-->
<property name="configLocation" value="sqlMapConfig.xml"></property>
</bean>
<!--扫描mapper所在的包 为mapper创建实现类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.itheima.mapper"/>
</bean>
2.将事务的控制交给spring容器进行声明式事务控制
<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jabc.datasource.DateSouceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置事务增强-->
<tx:advice id="txAdvice" >
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--配置事务织入-->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.itheima.service.impl.*.*(..))"
</aop:config>