首页 > 学院 > 开发设计 > 正文

初识Spring,配置spring的步骤以及所需要的jar包

2019-11-06 09:11:13
字体:
来源:转载
供稿:网友

SPRing是一个开源框架。为了解决企业应用开发的复杂性,而创建的,但现在已经不止应用于企业应用。

是一个轻量级的控制反转(IOC)和面向切面(AOP)的 容器框架

从大小与开销两方面而言sping是轻量级的。

通过反转(ioc)的技术达到松耦合的目的

提供了面向切面编程的丰富支持,允许通过分离应用的业务逻辑与系统级服务进行内聚性开发

包含并管理应用对象的配置和生命周期,这个意义上是一种容器。

将简单的组件配置,组合成为复杂的应用,这个意义上就是框架、

什么是Spring,轻量级:Spring 是非侵入性的,给予spring开发的应用中的对象可以不依赖于spring  api

------依赖注入(D---Dependency injection ,ioc)

-----面向切面编程(AOP----aspect oriented programming)

-----容器:spring 是一个容器,因为它包含并且管理应用对象的生命周期,

-----框架:spring实现了简单的组件配置组合成一个复杂的应用。在spring中可以使用xmljava注解组合这些对象。

-----站式:在ioc和aop的基础上可以整合各种企业用的开源框架和优秀的第三方类库(实际上spring本身也提供了展现层的springMVC和持久层的JDBC)

spring:业务层矿建,管理bean的java:new a.setXxx();思想:    ioc        aop        体验spring:下载类库        spring-framWorder-3.1.0.CI-1163-dependenies.zip(依赖项)        spring-framework-3.1.0.zip(核心包)        1.创建java项目        2.引入类库        spring            org.springframeworker.aop-3.1.0.RELEASE.jar            org.springframeworker.asm-3.1.0.RELEASE.jar            org.springframeworker.beans-3.1.0.RELEASE.jar            org.springframeworker.context-3.1.0.RELEASE.jar            org.springframeworker.context.support.RELEASE.jar            org.springframeworker.core-3.1.0.RELEASE.jar        在spring-framworder-3.1.0.CI-1163-dependenies.zip包中找到H:/day28 Spring徐培成/资料/spring-framework-3.1.0.CI-1163-dependencies/org.apache.commons/com.springsource.org.apache.commons.logging        com.springsource.org.apache.commons.logging-1,1.1.jar        3.创建一个类。                                package com.test.spring;                    /*GreetingSerivice                     *                      *                      * */                    public class GreetingService {                        public String greeting;                                            public String getGreeting() {                            return greeting;                        }                                            public void setGreeting(String greeting) {                            this.greeting = greeting;                        }                        public void sayGreeting(){                            System.out.println(greeting);                        }                    }                    4.创建App类                        package com.itcast.spirng;                                import com.test.spring.GreetingService;                                public class App {                    public static void main(String[] args){                        GreetingService gs=new GreetingService();                        gs.setGreeting("helloword");                        gs.sayGreeting();                    }                                    }        5.创建一个文件application.xml在src目录下        <?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-3.0.xsd">           <!-- 配置一个bean -->        <bean id="greetingService" class="com.test.spring.GreetingService">               <property name="greeting">                   <value>hello world</value>               </property>               <property name="serivice" ref="bye">  <!--对象之间的依赖关系-->               </property>               <property name="greeting2">                   <value>tom</value>               </property>          </bean>           <bean id="bye" class="com.test.spring.ByeSerivice">               <property name="bye" value="later"/>            </bean></beans>        6.实现spring方式实现            ApplicationContext ac=new ClassPathxmlApplicationContext("applicationContext.xml");            GreetingSerivice gs=(GreetingSerivice) ac.getBean("greetingSerivice");            gs.sayGreeting();            gs.sayGreeting2();            ByeSerivice bs=(ByteService)ac.getBean("byeSerivice");            bs.sayBye();        7.注意<property   name="bs" ref="byeSerivice"/> 方式表示对象之间的依赖关系        查看ide下注册的dtd/xsd文件,            windows---》prifrence---》xml catelog--->            在xsd文件从jar              spring    思想:        1.ioc:inverse of control,反转控制            反转:获得依赖的对象方式被反转了。                1).对象实例化问题。(spring问题)                2)组装对象的出发点               


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表