spring中的注解;
@Repository用于标注数据访问组件,即DAO组件;
例:
@Repository
public class VentorDaoImpl implements iVentorDao {
}
在一个稍大的项目中,如果组件采用xml的bean定义来配置,显然会增加配置文件的体积,查找以及维护起来也不太方便。
Spring2.5为我们引入了组件自动扫描机制,他在类路径下寻找标注了上述注解的类,并把这些类纳入进spring容器中管理。
它的作用和在xml文件中使用bean节点配置组件时一样的。要使用自动扫描机制,我们需要打开以下配置信息:
<?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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context /spring-context-2.5.xsd">
<context:component-scan base-package=”com.eric.spring”>
</beans>
@Repository用于标注数据访问组件,即DAO组件;
例:
@Repository
public class VentorDaoImpl implements iVentorDao {
}
在一个稍大的项目中,如果组件采用xml的bean定义来配置,显然会增加配置文件的体积,查找以及维护起来也不太方便。
Spring2.5为我们引入了组件自动扫描机制,他在类路径下寻找标注了上述注解的类,并把这些类纳入进spring容器中管理。
它的作用和在xml文件中使用bean节点配置组件时一样的。要使用自动扫描机制,我们需要打开以下配置信息:
<?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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context /spring-context-2.5.xsd">
<context:component-scan base-package=”com.eric.spring”>
</beans>
本文介绍Spring框架中@Repository注解的用途及其在数据访问组件中的应用方式。此外,还详细讲解了如何通过配置自动扫描机制来简化Spring项目的组件管理。
974

被折叠的 条评论
为什么被折叠?



