1. 程式人生 > >java中的@repository什麼意思?

java中的@repository什麼意思?

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>