一、Spring中注解的分类
二、spring基于xml的基本配置(无表现层)
三、在xml配置基础之上的第一步改进:使用少量注解
这一步做的改动有:
bean.xml文件中不再需要配置Service对象和Dao对象,而是直接使用@Repository及@Service注解,
再加上@Autowired注解,让spring框架为我们注入相对应的Service对象和Dao对象。
四、在xml配置基础之上的第二步改进:不再使用xml配置文件,改用配置类的形式
1、Spring中的新注解
2、spring和Junit的整合:对重复代码的处理
五、使用spring框架的注意事项
1、使用注解配置时,拿掉bean.xml文件的意思,并不是删掉该文件。而是仅保留一个约束,其他配置挪到配置类中去。
2、使用xml配置和注解配置的bean.xml文件中的约束是不一样的。
①使用xml配置:
<?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">
②使用注解配置:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">