2011-10-07 30 views
3

在下面的xml配置中,我有一個sql查詢需要注入empDAO。Spring 3.0基於Annonation的AutoWiring

<bean id="propertyPlaceholderConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>/WEB-INF/conf/db.properties</value> 
       <value>/WEB-INF/conf/query.properties</value> 
      </list> 
     </property> 
</bean> 

<bean id="empDAO" class="com.dao.EmployeeDAO"> 
    <!-- How to do Annotation-based autowire for the string--> 
     <property name="selectTradeQ" value="${select.emp}" /> 
</bean> 

我的問題是如何使用Annotation-autowire的字符串?有些東西像下面

//This is not possible ?? Then how to do this 
    <bean id="selectTradeQ" value="${select.emp}> 

回答

4
@Component 
public class EmployeeDAO { 
    @Value("${select.emp}") 
    private String selectTradeQ; 
} 
+0

感謝。這樣可行。 – james007