spring环境搭建
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环境搭建的更多相关文章
- Spring环境搭建之:导入jar包、配置文件名称及放置位置
Spring环境搭建之:导入jar包.配置文件名称及放置位置 现在项目开发中spring框架应用的还是比较多的,自己用的还不太熟练,每次用的时候总配置半天,总有些配置弄错,就找个时间总结以下,方便以后 ...
- 【Spring学习笔记-1】Myeclipse下Spring环境搭建
*.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...
- 【Spring环境搭建】在Myeclipse下搭建Spring环境-web开发
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...
- Spring之Spring环境搭建
Spring之Spring环境搭建 一.什么是Spring? Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spr ...
- SSH环境搭建之Spring环境搭建篇
SSH环境搭建之Spring环境搭建篇 一.引入Spring所使用的JAR文件 二.在src目录下创建beans.xml(Spring的容器文件) <?xml version="1.0 ...
- Spring环境搭建及简单demo
1. Spring框架简介(以下这段话可用于面试求职) Spring为JavaEE开发提供了一个轻量级的解决方案,主要表现为, IOC(或者叫做DI)的核心机制,提供了bean工厂(Spring容器) ...
- eclipse Spring环境搭建 spring tool suite
1.期初用intellij社区版,发现收费版才能开发Java EE. 2.使用eclipse按照网上的教程,在help->eclipse marketplace中搜索sts安装spring工具套 ...
- 01、Spring环境搭建
环境:SpringSource-Tool-3.9.9.Eclipse4.10.0 首先,我们需要解决的是Spring包的问题,我看了百度.CSDN很多都是直接一上来随便丢个包就可以安装了,搞得我弄了一 ...
- 一、spring 环境搭建
一.springtoolSuite4下载 1.概述 Spring Tools 4 是适用于您最喜欢的编码环境的下一代 Spring 工具.它主要从头开始重建,为开发基于 Spring 的企业应用程序提 ...
- spring环境搭建需要的插件-------Spring Tool Suite™ Downloads
下载地址http://spring.io/tools/sts/all 上面的是集成了eclipse的,所以文件比较大,下面的是单独的插件,下载之后打开eclipse,help->installN ...
随机推荐
- python3.6安装docx模块
1.下载 python_docx-0.8.6-py2.py3-none-any.whl 地址: http://www.lfd.uci.edu/~gohlke/pythonlibs/2.在这个网页的最下 ...
- pycharm Python Console调试 & django 调试
1.设置断点,然后debug 2.如果在运行中想修改变量,可以直接在pycharm中修改 如将列表的 13改成3,然后选中 Excuting Selection in console ...
- “tar: Removing leading `/’ from member names”的错误
“tar: Removing leading `/’ from member names”的错误 使用tar打bz2压缩的时候报的错误,解决方案:加入参数: P (大写的屁) # tar -jcPf ...
- Scrapy详解
一.爬虫生态框架 在管道传数据只能传字典和items类型. 将 上一return语句注释则会报错 如: 如上图,爬虫文件中有一个name属性,如果多个爬虫可以通过这个属性在管道控制分析的是哪个爬虫的 ...
- spring boot 整合js css 静态文件
一,添加配置 spring: application: name: interview-server resources: static-locations: file:config/statics ...
- SQL死锁操作
这两天数据库经常被锁,所以记录一下操作: 查看被锁表:select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) ...
- nginx 环境不支持thinkPHP
在linux+Nginx+mysql+PHP 新装的服务器下,不支持重写pathinfo功能 . 需要加入这个代码 让Nginx 支持重写功能 location / { if (!-e $reques ...
- JavaScript笔记1———js的一些常识
一.什么是js? js是一种运行于解释器中的解释型脚本语言. 二.js的组成部分? 1.ECMAScript-----这是js的核心 2.DOM-----让js可以对网页进行操作(例:对页面元素的增. ...
- mysql的sql_mode设置
参考官方文档: mysql可以为不同的客户端设置不同的sql_mode,并且每个应用能够设置他自己的会话级别的sql_mode.sql_mode会影响sql语法以及mysql显示数据的正确性. Whe ...
- Gatling实战(一)
对Gatling早有耳闻,据说比jmeter的性能要好很多,我第一次试用的时候因为本机安装的jdk版本不对无法跑起来,试用失败后,因为没时间就一直没继续研究了.我当时是去java官网下载最新的jdk覆 ...