src/config/ApplicationContext.xml

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
				http://www.springframework.org/schema/context
				 http://www.springframework.org/schema/context/spring-context-3.2.xsd
				http://www.springframework.org/schema/tx 
				http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    
    <!-- 加载配置JDBC文件 -->
	<context:property-placeholder location="classpath:datasource.properties" />
	<!-- 数据源 -->
    <bean id="dataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName">
    <value>${jdbc.driverClassName}</value>
     </property>
    <property name="url">
    <value>${jdbc.url}</value>
    </property>
    <property name="username">
    <value>${jdbc.username}</value>
    </property>
    <property name="password">
    <value>${jdbc.password}</value>
    </property>
    </bean>
    
     <!-- 下面这两个开启了自动扫描功能 -->
      <!-- 开启注解配置 即Autowried -->  
    <context:annotation-config/>  
    <!--    使用自动注入的时候要  添加他来扫描bean之后才能在使用的时候   -->
    <context:component-scan base-package="com.dao ,com.action"/>  
    
   <!--  添加事务的控制-->
    <tx:annotation-driven transaction-manager="transactionManager" />
 
    <!-- 在使用mybatis时 spring使用sqlsessionFactoryBean 来管理mybatis的sqlsessionFactory-->
    <!-- 而像这种使用接口实现的方式 是使用sqlsessionTemplate来进行操作的,他提供了一些方法 -->
    <bean id="sqlSessionFactory"  class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <!-- mybatis配置文件路径-->
    <property name="configLocation"  value=""/>   
    <!-- 实体类映射文件路径-->

     <property name="mapperLocations" value="classpath:mybatis/*.xml"/> 
 
    </bean>
    <!-- 配置sqlsession 产生这个实例就是通过 sqlsessionTemplate来实现的 -->    
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg index="0">
    <ref  bean="sqlSessionFactory"/>
    </constructor-arg>
    </bean>
   
    <!-- 事务 需要三件事才可以  一具体的事务实现着  二事务管理器  三  aop 事务控制  不起作用-->
    <!--  这里使用 全注释  事务 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">    
        <property name="dataSource" ref="dataSource" />    
后面还有 3 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。