发表于: 2016-08-27 11:10:35
1 2337
今天完成的事情:初步了解了spring,,spring是一站式的开源框架,主要包括IOC和AOP,IOC是控制反转,即把对象的控制权交给spring来管理,AOP是面向切面编程,是对面向对象功能的延伸。
我用的是spring3.2版本,使用时需要创建动态WEB工程,然后再导入相应的四个jar包:
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
以及开发日志的记录包
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
再配置ApplicationContext.xml配置文件
先是配置bean的约束schema
<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">
然后配置bean,beans里可以配置多个bean,每个bean可以定义一个实例
<bean id="userService" class="cn.ptteng.spring.HelloServiceImpl">
<!-- 使用property注入属性 -->
<property name="info" value="葡萄藤(磁盘路径)"/>
</bean>
id是bean的唯一标识,容器对bean的管理、访问以及对该bean的依赖关系都算通过id来完成
class是实现类的全限定名,通过配置bean,spring能找到实现类和管理
name属性是为了传入参数,参数的值为value的值
明天计划的事情:继续学习spring的bean的生命周期以及bean的属性的注入
遇到的问题:
已解决:传入的参数无法打印出来,是参数info在自动生成set方法时自动变为了InFo,导致无法识别,后面把InFo改为setInfo解决
收获:spring是基于mybatis的,通过spring的学习感觉mybatis有了更深入的了解
评论