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

spring环境搭建的更多相关文章

  1. Spring环境搭建之:导入jar包、配置文件名称及放置位置

    Spring环境搭建之:导入jar包.配置文件名称及放置位置 现在项目开发中spring框架应用的还是比较多的,自己用的还不太熟练,每次用的时候总配置半天,总有些配置弄错,就找个时间总结以下,方便以后 ...

  2. 【Spring学习笔记-1】Myeclipse下Spring环境搭建

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

  3. 【Spring环境搭建】在Myeclipse下搭建Spring环境-web开发

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  4. Spring之Spring环境搭建

    Spring之Spring环境搭建 一.什么是Spring? Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spr ...

  5. SSH环境搭建之Spring环境搭建篇

    SSH环境搭建之Spring环境搭建篇 一.引入Spring所使用的JAR文件 二.在src目录下创建beans.xml(Spring的容器文件) <?xml version="1.0 ...

  6. Spring环境搭建及简单demo

    1. Spring框架简介(以下这段话可用于面试求职) Spring为JavaEE开发提供了一个轻量级的解决方案,主要表现为, IOC(或者叫做DI)的核心机制,提供了bean工厂(Spring容器) ...

  7. eclipse Spring环境搭建 spring tool suite

    1.期初用intellij社区版,发现收费版才能开发Java EE. 2.使用eclipse按照网上的教程,在help->eclipse marketplace中搜索sts安装spring工具套 ...

  8. 01、Spring环境搭建

    环境:SpringSource-Tool-3.9.9.Eclipse4.10.0 首先,我们需要解决的是Spring包的问题,我看了百度.CSDN很多都是直接一上来随便丢个包就可以安装了,搞得我弄了一 ...

  9. 一、spring 环境搭建

    一.springtoolSuite4下载 1.概述 Spring Tools 4 是适用于您最喜欢的编码环境的下一代 Spring 工具.它主要从头开始重建,为开发基于 Spring 的企业应用程序提 ...

  10. spring环境搭建需要的插件-------Spring Tool Suite™ Downloads

    下载地址http://spring.io/tools/sts/all 上面的是集成了eclipse的,所以文件比较大,下面的是单独的插件,下载之后打开eclipse,help->installN ...

随机推荐

  1. 2018-2019-2 网络对抗技术 20165321 Exp2 后门原理与实践

    基础问题回答 (1)例举你能想到的一个后门进入到你系统中的可能方式? 答:网络钓鱼植入木马. (2)例举你知道的后门如何启动起来(win及linux)的方式? 答:绑定在合法软件上启动. (3)Met ...

  2. C++ MFC万能的类向导

    MFC的类向导 只要你掌握了类向导,你基本就已经掌握了MFC了,毕竟布局和代码都是自动生成,再加上C++基础上手还是挺快的,剩下的就是多多练习了. 转自: https://blog.csdn.net/ ...

  3. TextField widgets require a Material widget ancestor

    TextField widget需要被包裹在Scaffold widget中,否则会报错

  4. 客户端不能连接MySQL - 2003-Can't connect to MySQL server on '192.168.43.180'(10060 "Unknown error")

    客户端不能连接MySQL 场景: 数据库(此处以MySQL为例)安装在虚拟机里面,在宿主机上进行连接数据库的时候始终不能连接,但在虚拟机中使用正常. 针对上面的场景: 1. 在虚拟机里面可以正常使用M ...

  5. C#中DataTable与XML格式的相互转换

    1.DataTable转换成XML public string ConvertDataTableToXML(DataTable xmlDS) { MemoryStream stream = null; ...

  6. noVNC支持手机自带键盘输入

    代码修改说明 novnc的web链接类似为:http://192.168.1.177:6080/vnc_auto.html?token=105356fa-bbe3-43e4-a0ce-7703dc42 ...

  7. 【数据结构】算法 Maximum Subarray

    最大子数组:Maximum Subarray 参考来源:Maximum subarray problem Kadane算法扫描一次整个数列的所有数值,在每一个扫描点计算以该点数值为结束点的子数列的最大 ...

  8. liunx驱动----构造和运行模块

    以hello world模块为例 #include <linux/init.h> #include <linux/module.h> //在执行 insmod hlello 的 ...

  9. js中的数组方法

    数组的方法有数组原型方法,也有从object对象继承来的方法,这里我们只介绍数组的原型方法,数组原型方法主要有以下这些: join()push()和pop()shift() 和 unshift()so ...

  10. 原创《weex面向未来的架构》

    最近一直在做weex的调研工作,整理之后给公司做了一次技术分享. 分享内容如下: 1:Weex是什么? 2:  Weex目前能做什么? 3:  Weex 如何调试 4:  剖析一下Weex原理 5: ...