Spring HelloWorld

作者: 逗比寨主 | 来源:发表于2019-07-15 18:38 被阅读0次

1.Spring是什么

(1)轻量级的框架:Spring是非侵入性的,基于Spring开发的应用对象可以不依赖Spring的API

(2)依赖注入 IOC

(3)面向切面编程 AOP

(4)容器:因为它包含并且管理应用对象的生命周期

(5)框架:Spring实现了使用简单的组件配置组合成一个复杂的应用,在Spring中可以使用XML和Java注解组合这些对象

(6)一站式:在IOS和AOP的基础上可以整合各种企业应用的开源框架和优秀的第三方类库(Spring自身也提供了展现层的Spring MVC和持久层的Spring JDBC)

2.第一个HelloWorld程序

Step1——> 引入Jar包:

Step2——> src目录下创建applicationContext.xml

Step3——>配置xml

<?xmlversion="1.0" encoding="UTF-8"?>

<beansxmlns="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-->

<beanid="hellowWorld"class="com.spring.note.HellowWorld">

<propertyname="name"value="Spring"></property>

</bean>

</beans>

ApplicationContextctx=newClassPathXmlApplicationContext("applicationContext.xml");

HellowWorldhellowWorld=(HellowWorld)ctx.getBean("hellowWorld");

hellowWorld.hello();

输出结果:Hello World! Spring

Step4——>调用Spring的IOC容器对象,并根据ID获取实例

相关文章

网友评论

    本文标题:Spring HelloWorld

    本文链接:https://www.haomeiwen.com/subject/qksokctx.html