xml文件的配置:
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
">
<context:annotation-config />//打开注解注入
<context:component-scan base-package="com.dzy"></context:component-scan>//打开自动扫描
@service用于标注业务层组件
@controller 用于标注控制层组件
@repository 用于标注dao层组件
@component用于标注不确定层组件
@Autowired可以标注在属性和set方法上,先去查找类型
@Qualifier(" ")以名字为查找对象,如果找不到,抛出异常。
@resource优先根据id查找