Spring使用技巧

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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章