Spring使用技巧

来源:互联网 发布:真人cs漆弹枪淘宝店 编辑:程序博客网 时间:2024/05/17 21:50
1.注入List类型值protected List<String> supportCodes;public void setSupportCodes(List<String> supportCodes) {this.supportCodes = supportCodes;}public boolean support(String productCode) {if(null == supportCodes || supportCodes.isEmpty()) {return false;}for(String code : supportCodes) {if(code.equals(productCode)) {return true;}}return false;}xml如下: <property name="supportCodes"><list><value>FI16006</value><value>FI16005</value><value>FI16004</value></list></property>2.注入Map类型值 private Map<String, String> instProductPos; <bean id= "instProductPos" class ="java.util.HashMap"> <constructor-arg> <map> <entry key= "Funds" value="com.payment.lc.pcs.po.ProductionFundsPo" /> <entry key= "Insurance" value="com.payment.lc.pcs.po.ProductionInsurancePo" /> <entry key= "YueGuJiao" value="com.payment.lc.pcs.po.ProductionYueGuJiaoPo" /> </map> </constructor-arg> </bean > private Map<String, MemcachedClient> clientMap; <bean id= "pcsMemeryCacheClient" class="com.payment.lc.pcs.cache.impl.MemeryCacheClient" > <property name= "clientMap"> <map> <entry key= "production"> <ref bean= "pcsMemeryClient" /> </entry> </map> </property> </bean>3.注入threadPoolTaskExecutor(建议勿对更新操作使用)threadPoolTaskExecutor.execute(new Runnable() {            public void run() {                //处理            }        });<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">                <property name="corePoolSize" value="5" />                <property name="maxPoolSize" value="20" />                               <property name="queueCapacity" value="200" />                        <property name="keepAliveSeconds" value="300" />                <property name="rejectedExecutionHandler">                        <bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />                </property>        </bean>
4.注入List值<property name="accountIdList">        <list>        <value>70000001</value>        </list>        </property>


0 0
原创粉丝点击