zoukankan      html  css  js  c++  java
  • spring中xml配置方式和注解annoation方式(包括@autowired和@resource)的区别

    xml文件中配置itemSqlParameterSourceProvider是可以的:

    
    

    <bean id="billDbWriter"
    class="com.aa.bb.AABatchWriter">
    <property name="dataSource" ref="dataSource" />
    <property name="sql"
    value="insert into bills(id,user_id,fees,paid_fees,unpaid_fees,pay_status) values(:id,:user.id,:fees,:paidFees,:unpaidFees,:payStatus)" />
    <property name="itemSqlParameterSourceProvider"
    ref="itemSqlParameterSourceProvider" />

    
    

    <bean id="itemSqlParameterSourceProvider"
    class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />

    但是假如放到java代码中,用@Resource和@AutoWired都引用不到itemSqlParameterSourceProvider,会报错:

    public class AABatchWriter<T> implements ItemWriter<T> {
        
        @Resource
        BeanPropertyItemSqlParameterSourceProvider itemSqlParameterSourceProvider;
    
        /* (non-Javadoc)
         * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
         */
        public void write(List<? extends T> items) throws Exception {
            // TODO Auto-generated method stub
            
        }
        
    }
  • 相关阅读:
    Python异常处理
    奇异值分解(SVD)详解及其应用
    上楼梯问题
    Python面向对象(特殊成员)
    Best Time to Buy and Sell Stock II
    String to Integer (atoi)
    Gas Station
    N-Queens II
    Letter Combinations of a Phone Number
    N-Queens
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/9408675.html
Copyright © 2011-2022 走看看