一、Spring是什么?

.Spring是一个开源的框架

.是一个IOC(DI)和AOP容器的框架

.这个框架是为了简化企业级应用开发而生的,使用Spring可以使简单的JavaBean实现以前只有EJB才能实现的功能

.轻量级:Spring是非侵入式的,基于Spring开发应用中的对象可以不依赖于Spring的API

.依赖注入(DI、IOC)

.面向切面编程(AOP)

.容器,Spring是一个容器,因为他包含并且管理应用对象的生命周期

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

.一站式,在IOC和AOP的基础上可以整合各种企业应用的开源框架和优秀的第三方类库(实际上Spring自身也实现了展现层的SpringMVC和SpringJDBC)

 

二、安装Spring tool suite

他是eclipse的插件,使用这个插件可以更好的开发基于Spring的应用,比如可以新建Spring的配置文件

安装插件的步骤:

Spring(1)

三、搭建Spring的开发环境

.添加jar包

Spring(1)

.Spring的配置文件:

一个典型的Spring项目需要创建一个或多个Spring配置文件,这些配置文件用于在SpringIOC容器中配置Bean对象,Bean的配置文件可以放在classpath或者其他的路径下

四、创建简单的Spring项目

l类文件:

package cn.jc.spring.beans;

public class HelloWorld {
private String name;

@Override
public String toString() {
  return "HelloWorld [name=" + name + "]";
}
public void setName(String name) {
  this.name = name;
}
public HelloWorld() {
}
}

Spring配置文件:

<bean id="helloworld" class="cn.jc.spring.beans.HelloWorld">
  <property name="name" value="caoyang"></property>
</bean>

测试:

public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans-applicationContext.xml");
HelloWorld helloworld= (HelloWorld )ctx.getBean("helloworld");
System.out.println(helloworld.toString());
}

 

相关文章:

  • 2021-06-28
  • 2022-01-13
  • 2021-05-23
  • 2022-01-13
  • 2021-07-23
  • 2021-05-18
  • 2021-06-19
  • 2022-03-10
猜你喜欢
  • 2021-07-30
  • 2021-11-29
  • 2021-12-19
  • 2021-05-21
  • 2021-06-25
  • 2021-07-11
  • 2022-02-06
相关资源
相似解决方案