官网 : http://spring.io/
官方下载地址 : https://repo.spring.io/libs-release-local/org/springframework/spring/
GitHub : https://github.com/spring-projects
1 spring入门程序
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
</dependency>
</dependencies>
<?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">
</beans>
2 IOC创建对象方式
2.1通过无参构造方法来创建
<bean id="userMysqlImpl" class="com.zs.dao.UserMySqlDaoImpl"/>
<bean id="userOrcalImpl" class="com.zs.dao.UserOrcalDaoImpl"/>
2.2通过有参构造方法来创建
<bean id="user" class="com.zs.pojo.User">
<constructor-arg name="name" value="zs"/>
</bean>
3 Spring简单配置
3.1配置别名
<alias name="hello" alias="hello2"/>
<bean id="hello" name="hello2, hello3, hello4" class="com.zs.Hello">
<property name="userName" value="赵帅"/>
</bean>
3.2 通过import,将到多个配置文件导入为一个文件
4 DI
<?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="address" class="com.zs.pojo.Address"/>
<bean id="student" class="com.zs.pojo.Student">
<property name="name" value="zs"/>
<!-- private Address address;-->
<property name="address" ref="address"/>
<!-- private String[] books;-->
<property name="books">
<array>
<value>西游记</value>
<value>红楼梦</value>
<value>水浒传</value>
</array>
</property>
<!-- private List<String> hobbys;-->
<property name="hobbys">
<list>
<value>听歌</value>
<value>看电影</value>
<value>爬山</value>
</list>
</property>
<!-- private Map<String,String> card;-->
<property name="card">
<map>
<entry key="中国邮政" value="456456456465456"/>
<entry key="建设" value="1456682255511"/>
</map>
</property>
<!-- private Set<String> games;-->
<property name="games">
<set>
<value>LOL</value>
<value>BOB</value>
<value>COC</value>
</set>
</property>
<!-- private String wife;-->
<property name="wife">
<null/>
</property>
<!-- private Properties info;-->
<property name="info">
<props>
<prop key="学号">20190604</prop>
<prop key="性别">男</prop>
<prop key="姓名">小明</prop>
</props>
</property>
</bean>
</beans>
Student(name=zs, address=Address(address=null), books=[西游记, 红楼梦, 水浒传], hobbys=[听歌, 看电影, 爬山], card={中国邮政=456456456465456, 建设=1456682255511}, games=[LOL, BOB, COC], wife=null, info={学号=20190604, 性别=男, 姓名=小明})
5 使用注解自动装配
在spring4之后,想要使用注解形式,必须得要引入aop的包:org.springframework:spring-aop:5.2.0.RELEASE