<?xml version="1.0" encoding="UTF-8"?>
这个相信不用说了version是版本号,貌似一直都是1.0,而后面的则是编码格式,为UTF-8,在安装mysql的时候选择的话,相信大部分选得也都是UTF-8的编码格式吧
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
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.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
这一大堆不知道干吗的,不过貌似都有,是必须配置的,貌似Android的xml文件中也有一些这玩意,这个就不去深究了
<context:component-scan base-package="cn.edu.sjzc"></context:component-scan>
这个是包名
<!-- sessionFactory 的配置-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
这个是用来读取hibernate中bean实例的,随着sping的启动,将session工厂中的bean实例读取到内存中,并且创建相应的bean对象
注意配置的时候一定要写对hibernate的文件路径
<!-- trasactionManager的定义 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean>
这是对数据库的操作,不知道大家发现没有,开始和结束都是用的bean,感觉这其实就是对应的相应的bean,和bean实例有相应的映射,允许Spring利用hibernate对bean实例进行相应的操作,完成数据库的修改
<!-- 定义事物的特性 :事物的超市时间,事物是否只读,回滚定义等-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 所有方法使用默认事物特性 -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
意思是这个事物advice的管理者为transactionManager,你从配置文件中应该能够找到一个ID为transactionManager的bean,而所有使用的方法都是默认的事物的特性
<!-- 配置哪些对象的哪些方法需要添加事物管理能力 --> <aop:config> <aop:pointcut id="allServiceMethods" expression="execution(* cn.edu.sjzc.service.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethods"/> </aop:config>规定相应的aop去引用上面定义的实物
这个整个的配置文件都是用bean包起来的,可想而知,sping是操作的相应的实例