欢迎使用CSDN-markdown编辑器

来源:互联网 发布:生酮饮食都吃什么 知乎 编辑:程序博客网 时间:2024/06/05 01:17

Spring框架介绍:
Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的。(Lightweight)的容器(Container),它是实现IoC(Inversion of Control)容器和非入侵性(No intrusive)的框架,并提供AOP(Aspect-oriented programming)概念的实现方式;提供对持久层(Persistence)、事物(Transcation)的支持;提供MVC Web框架的实现,并对一些常用的企业服务API(Application Interface)提供一致的模型封装,是一个全方位的应用程序框架(Application Framework),除此之外,对现存的各种框架(Structs、JSF、Hibernate、Ibatis、Webwork等),Spring也提供了与他们相整合的方案。
Spring 作者:Rod Johnson;
官方网站:http://spring.io/
最新开发包及文档下载地址:http://repo.springsource.org/libs-release-local/org/springframework/spring/
核心思想:IOC 控制反转;AOP 面向切面;
Spring版HelloWorld:

创建一个HelloWorld类

public class HelloWorld {    public void say(){        System.out.println("Hello, Spring4!");    }}

配置Beans.xml文件文件

<?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">    <bean id="helloWorld" class="com.test.HelloWorld"></bean></beans>

测试

public static void main(String[] args) {        //加载beans.xml配置文件        ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");        //只需要通过bean中设定的id,可以生成对象        HelloWorld helloWorld=(HelloWorld)ac.getBean("helloWorld");        helloWorld.say();    }    }
原创粉丝点击