一个典型的Spring的applicationcontext.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"
 xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

 

 <!-- Session 工厂 -->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation"
   value="classpath:hibernate.cfg.xml"><!-- 可以不要配置文件(hibernate.cfg.xml),直接写在这个Spring的配置文件中 -->
  </property>
 </bean>


 <!-- 模板 -->
 <bean id="hibernateTemplate"
  class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>


 <!-- 事务器 -->
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>

 

 <!-- 对外代理 -->

 

 <!-- 1,用户管理 -->
 <bean id="userDaoImp"
  class="com.ygkq.usermanager.model.dao.hibernate.UserDaoImp">
  <property name="hibernateTemplate" ref="hibernateTemplate" />
 </bean>

 <bean id="userServiceTarget"
  class="com.ygkq.usermanager.model.service.spring.UserServiceImp">
  <property name="userdao">
   <ref local="userDaoImp" />
  </property>
 </bean>

 <bean id="userService"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
   <ref local="transactionManager" />
  </property>
  <property name="target">  
   <ref local="userServiceTarget" />
  </property>
  <property name="transactionAttributes">
   <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>
 
</beans>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SpringapplicationContext.xml 配置文件一个非常重要的文件,它用于配置Spring应用程序的各种组件和依赖关系。这个文件通常位于Spring项目的 classpath 下,因此Spring容器可以轻松地加载和解析它。 下面是一个简单的 applicationContext.xml 配置文件示例: ```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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 配置一个名为 "userService" 的 bean,其类为 com.example.UserService --> <bean id="userService" class="com.example.UserService"/> <!-- 配置一个名为 "userRepository" 的 bean,其类为 com.example.UserRepository --> <bean id="userRepository" class="com.example.UserRepository"/> <!-- 配置一个名为 "userController" 的 bean,其类为 com.example.UserController --> <bean id="userController" class="com.example.UserController"> <!-- 将 userService 和 userRepository 注入到 userController 中 --> <property name="userService" ref="userService"/> <property name="userRepository" ref="userRepository"/> </bean> </beans> ``` 在这个示例中,我们定义了三个 bean: - 名为 `userService` 的 bean,它的类为 `com.example.UserService`。 - 名为 `userRepository` 的 bean,它的类为 `com.example.UserRepository`。 - 名为 `userController` 的 bean,它的类为 `com.example.UserController`。我们使用 `<property>` 元素将 `userService` 和 `userRepository` 注入到 `userController` 中。 通过这种方式,我们可以定义和组装Spring应用程序中的各种组件和依赖关系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值