一般写Spring的文章,会先说一下,IOC容器、DI等概念性的内容。但是由于是个人的笔记,就直入主题。就是要熟悉Spring的XML是怎么配的。[https://gitee.com/gao_xi/spring-demo1/tree/master/](https://gitee.com/gao_xi/spring-demo1/tree/master/)
1.开发环境
JDK1.8
Maven3.6
IDEA2019.3
2.搭建步骤
2.1创建工程
2.2xml文件配置
<?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="book" class="com.gao.Book"></bean>
</beans>
2.3代码编写
/**
* @author GaoXi
* @date 2021/8/13 19:31
*/
public class Book {
public void sayHello() {
System.out.println("Hello Spring5");
}
}
/**
* @author GaoXi
* @date 2021/8/13 19:33
*/
public class Starter {
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("config.xml");
Book book = applicationContext.getBean("book", Book.class);
book.sayHello();
}
}
3.如何手动下载Spring的相关jar包