spring部分:applicationContext.xml文件配置

1.配置数据源 dataSource

<!-- 配置数据源 -->
<bean />
</bean>

2.配置sqlSessionFactory,
2.1 引入dataSource,
2.2 自动扫描mappers.xml文件,
2.3 引入mybatis配置文件

<!-- 配置mybatis的sqlSessionFactory -->
<bean ></property>
</bean>

3.配置dao扫描器,扫描/mappers/*.xml对应的mapper接口类,需要引入sqlSessionFactory

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <property name="basePackage" value="com.java.user.dao" />
  <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

4.配置事务

<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean />
</bean>

 

<!-- 配置事务通知属性 -->
<tx:advice />
  </tx:attributes>
</tx:advice>

<!-- 配置事务切面 -->
<aop:config>
  <aop:pointcut />
</aop:config>

 

相关文章:

  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-10-31
  • 2021-07-21
猜你喜欢
  • 2021-06-16
  • 2021-06-30
  • 2021-12-29
  • 2021-05-30
  • 2021-12-07
  • 2021-09-15
  • 2022-01-19
相关资源
相似解决方案