1.导入jar包:

2.配置文件 — applicationContext.xml:

   添加schema约束,位置:spring-framework-3.2.0.RELEASE—》docs—》spring-framework-reference—》html—》xsd-config.html

再配置service

<?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">
<!-- 配置service
<bean> 配置需要创建的对象
id :用于之后从spring容器获得实例时使用的
class :需要创建实例的全限定类名
-->
<bean id="userServiceId" class="com.itheima.a_ioc.UserServiceImpl"></bean>
</beans>

applicationContext.xml

其次,里面可以配置加载jdbc属性文件、数据源、spring框架用于整合Hibernate的工厂bean、事务管理器、组件扫描、引入注解解析器、 事务注解 等。如:

<?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:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 加载jdbc属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/> <!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}"/>
<property name="jdbcUrl" value="${jdbcUrl}"/>
<property name="user" value="${user}"/>
<property name="password" value="${password}"/>
</bean>
<!-- spring框架用于整合Hibernate的工厂bean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 注入Hibernate相关的属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 注入Hibernate的映射文件 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/itheima/bos/domain</value>
</list>
</property>
</bean> <!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!-- 组件扫描 -->
<context:component-scan base-package="com.itheima.bos"/>
<!-- 引入注解解析器 -->
<context:annotation-config/>
<!-- 事务注解 -->
<tx:annotation-driven />
</beans>

applicationContext.xml

最新文章

  1. fiddler发送post请求
  2. cnentos中进行bond网卡配置,一切配置无问题,就是ping不通宿主机
  3. 利用扩展事件进行调优和Troubleshooting PPT分享
  4. python画图—黑板客老师课程学习
  5. 二维码相关工具Qrcode笔记
  6. 自定义UIPageControl圆点的图片
  7. Java常用类:String
  8. contiki Makefile.include 四个关注点&lt;contiki学习之二&gt;
  9. Python的包管理工具Pip
  10. 关于异或(Xor)的一点笔记
  11. Blend4精选案例图解教程(四):请给我路径指引
  12. 【Map】Double Queue
  13. DMI ( Dynamic Method Invocation )
  14. python基础===Python性能优化的20条建议
  15. 敏捷冲刺每日报告--day2
  16. 移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究
  17. 使用Spring的@Scheduled实现定时任务参数详解
  18. binlog和redo log日志提交
  19. Benefit UVA - 11889(已知LCM和其中一个数,求另一个数)
  20. 如何在CentOS系统中安装配置SNMP服务

热门文章

  1. C语言之指针若干问题
  2. 从零开始一起学习SLAM | 掌握g2o边的代码套路
  3. Cocos Creator_继承组件单例
  4. springmvc中的一些服务器报错
  5. jOrgChart二叉树效果
  6. UGUI中UI与模型混合显示
  7. noVNC支持手机自带键盘输入
  8. 【数据结构】算法 LinkList (Reverse LinkedList) Java
  9. 机器学习算法GBDT
  10. 向 Nginx 主进程发送 USR1 信号