一个轻量级的控制反转(IoC)和面向切面(AOP)的容器(框架)。
模块的介绍:后面会对各个模块进行介绍:持续更新~~~~~~~~~~
注 : spring 需要导入commons-logging进行日志记录 . 我们利用maven , 他会自动下载对应的依赖项 .
1. 导入Jar包
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.8.RELEASE</version> </dependency>为了代码编写方便,我这里多引入了 junit的模块:junit模块方便后面进行测试
2. 编写实体类
package com.hls.pojo; public class Hello { private String name; public void show(){ System.out.println(name); } }3. 编写配置文件
<?xml version="1.0" encoding="UTF-8"?> <!--suppress ALL --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <!-- 由 Spring容器创建该类的实例对象 --> <bean id="personDao" class="com.hls.pojo.Hello" > <property name="name" value="hello"></property> </bean> </beans>
4. 进行测试
import com.hls.pojo.Hello; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class test { @Test public void test1() { String resour="beans.xml"; ApplicationContext applicationContext=new ClassPathXmlApplicationContext(resour); Hello h=(Hello)applicationContext.getBean("personDao"); h.show(); } }运行测试,打印出hello就可以 了