SSM配置文件的注意事项

----------------------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>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值