Ⅰ spring全注解的xml 文件该怎么写
<?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:aop=" http://www.springframework.org/schema/aop"
xmlns:tx=" http://www.springframework.org/schema/tx"
 
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 声名式事务①:添加常用命名空间声明 --><!-- ***********************配置和SessionFactory************************ --> <bean id="data"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
  </property>
  <property name="url"
   value="jdbc:sqlserver://localhost:1433;databaseName=epet">
  </property>
  <property name="username" value="sa"></property>
  <property name="password" value=""></property>
 </bean>
 
 <bean id="sf"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="data"></ref>
  </property>
  <property name="mappingResources">
   <list>
    <value>entity/PetInfo.hbm.xml</value>
    <value>entity/PetDiary.hbm.xml</value>
    <value>entity/PetType.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect
    </prop>
    <!-- 配置<cache usage="read-only"/>后,配置Hibernate缓存机制属性 -->
    <prop key="hibernate.cache.provider_class">
    org.hibernate.cache.HashtableCacheProvider
    </prop>
   </props>
  </property>
 </bean>
 
<!-- ***************************配置各层依赖注入关系******************************** -->
 
 <!-- Dao层依赖于SessionFactory,SessionFactory注入Dao层 -->
  <bean id="petInfoDao" class=".PetInfoDaoImpl" >
   <property name="sessionFactory">
    <ref bean="sf" />
   </property>
  </bean>
  <bean id="petDiaryDao" class=".PetDiaryDaoImpl" >
   <property name="sessionFactory">
    <ref bean="sf" />
   </property>
  </bean>
  <bean id="petTypeDao" class=".PetTypeDaoImpl" >
   <property name="sessionFactory">
    <ref bean="sf" />
   </property>
  </bean>
 <!-- Dao层依赖于SessionFactory,SessionFactory注入Dao层 -->
 
 <!-- Biz层依赖于Dao层,Dao层注入Biz层 -->
  <bean id="petInfoBiz" class="biz.PetInfoBizImpl" >
   <property name="petInfoDao">
    <ref bean="petInfoDao" />
   </property> 
  </bean>
  
  <bean id="petDiaryBiz" class="biz.PetDiaryBizImpl">
   <property name="petDiaryDao" ref="petDiaryDao" />
  </bean>
  
  <bean id="petTypeBiz" class="biz.PetTypeBizImpl">
   <property name="petTypeDao" ref="petTypeDao" />
  </bean>
 <!-- Biz层依赖于Dao层,Dao层注入Biz层 -->
 
 <!-- ③配置Action依赖于Biz层,Biz层注入Action -->
  <bean name="/PetAction" class="web.action.PetAction">
   <!-- Biz注入Action -->
   <property name="petInfoBiz" ref="petInfoBiz" />
   <property name="petDiaryBiz" ref="petDiaryBiz"></property>
   <property name="petTypeBiz" ref="petTypeBiz"></property>
  </bean>
  
  <bean name="/DiaryAction" class="web.action.DiaryAction">
   <property name="petDiaryBiz" ref="petDiaryBiz"></property>
   <property name="petInfoBiz" ref="petInfoBiz"></property>
  </bean>
  
  <bean name="/DoLogAction" class="web.action.DoLogAction">
   <property name="petInfoBiz" ref="petInfoBiz"></property>
  </bean>
  
  <bean name="/DoTrainingAction" class="web.action.DoTrainingAction">
   <property name="petInfoBiz" ref="petInfoBiz"></property>
  </bean>
  
  <bean name="/IndexAction" class="web.action.IndexAction">
   <property name="petInfoBiz" ref="petInfoBiz"></property>
   <property name="petDiaryBiz" ref="petDiaryBiz"></property>
   <property name="petTypeBiz" ref="petTypeBiz"></property>
  </bean>
 <!-- ③配置Action依赖于Biz层,Biz层注入Action -->
 
<!-- ****************************配置声明式事务************************************ --><!-- 声名式事务②:定义事务管理器 -->
<bean id="myHibTransactionManager"
 class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 <property name="sessionFactory" ref="sf" />
</bean><!-- 声名式事务③:定义事务通知,声明事务规则 -->
<tx:advice id="txAdvice" transaction-manager="myHibTransactionManager">
 <tx:attributes>
  <tx:method name="add*" propagation="REQUIRED" />
  <tx:method name="del*" propagation="REQUIRED" />
  <tx:method name="update*" propagation="REQUIRED" />
  <tx:method name="do.*" propagation="REQUIRED" />
  <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
 </tx:attributes>
</tx:advice><aop:config>
 <!-- 声名式事务④:定义切面,指定哪些方法应用以上规则 -->
 <aop:pointcut id="bizMethods" expression="execution(* biz.*.*(..))" />
 <!-- 声名式事务⑤:将事务通知和切面组合 -->
 <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
</aop:config><!-- ******************************配置AOP方面代码******************************** --><!-- AOP实现: ①定义原Bean(实现类) 
 <bean id="petInfoBizTarget" class="biz.PetInfoBizImpl">
  <property name="petInfoDao" ref="petInfoDao"></property>
 </bean>-->
 <!-- AOP实现: ②定义通知 -->
 <bean id="lotteryAdvice" class="aop.LotteryAdvice">
  <property name="petInfoDao" ref="petInfoDao"></property>
 </bean>
 <bean id="diaryAdvice" class="aop.DiaryAdvice">
  <property name="petInfoDao" ref="petInfoDao"></property>
 </bean> <!-- AOP实现: ③定义代理类 -->
 <bean id="petInfoBizProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
  <!-- 被代理的接口 -->
  <property name="proxyInterfaces">
  <list>
   <value>biz.PetInfoBiz</value>
   <value>biz.PetDiaryBiz</value>
  </list>
  </property>
  <!-- 织入的通知列表 -->
  <property name="interceptorNames">
   <list>
    <value>lotteryAdvice</value>
    <value>diaryAdvice</value>
   </list>
  </property>
  <!-- 被代理的原Bean -->
  <property name="target">
  <list>
   <ref bean="petInfoBiz"/>
   <ref bean="petDiaryBiz"/>
  </list>
  </property>
 </bean></beans>
Ⅱ springxml文件怎么配置
对于大多数的应用,从表现层的action,到持久层的DataSource,都被Spring 作为
bean 管理。如果这些bean 被配置在同一个文件中,阅读及维护该配置文件将是一件非
常有挑战的事情。
因此, Spring 建议:将一个大的配置文件分解成多个小的配置文件,使每个配置文
件仅仅管理功能近似于bean; 这样不仅可以分散配置文件,降低修改配置文件的风险,
而且更符合"分而治之"的软件工程原理。
多个配置文件最终需要汇总, ApplicationContext提供如下方式来汇总多个配置文件:
.使用App1icationContext 加载多个配置文件。
• Web 应用启动时加载多个配置文件。
• XML 配置文件中导入其他配置。
1 ApplicationContext 加载多个配置文件 
ApplicatonContext 的常用实现类有如下两个:
• ClassPathXm1 ApplicationContext 。
•  。
这两个类都可以用来加载多个配置文件,它们的构造器都可以接收一个数组,并在
该数组中存放多个配置文件。 可采用如下代码加载多个
配置文件:
Ⅲ java问题:我想要利用spring 获得xml中全部的bean,让它返回一个数组。spring我没学完,不知道怎么做
用循环呗,把所有bean的名字写到一个String[] beans里,对这个数组进行解析,得到bean的名字,然后
用getBean(beans[i])