您的位置:首页 > 移动开发

从applicationContext.xml到beanfactiory 谈Spring从配置文件中获取bean

2014-10-21 16:06 806 查看
Spring@Autowired注解与自动装配 - - 博客频道 - CSDN.NET
http://blog.csdn.net/heyutao007/article/details/5981555
很早就想写一下Spring的反射了,一直没有机会写。

It's the time!

如何开始呢?先查了一下:

spring里头各种获取ApplicationContext的方法 - xieyuooo的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/xieyuooo/article/details/8473503
ApplicationContext_百度百科
http://baike.baidu.com/view/9188914.htm
感觉收获一般般啊,还是老方法!

find 代码吧!

一切从SpringContextUtil开始。

还记得之前的缓存方法吗,那里面有一句话:

GoodsInfoDao goodsInfoDao = (GoodsInfoDao) SpringContextUtil.getBean("goodsInfoDaoImpl");

从名字就可以看出,是接口指向实现的一个类似new的方法,这里就直接用了从配置文件中获取bean的方式。

springcontextutil:

package com.umpay.hfmng.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContextUtil implements ApplicationContextAware {
	  private static ApplicationContext applicationContext;     //Spring应用上下文环境
	 
	  /**
	  * 实现ApplicationContextAware接口的回调方法,设置上下文环境  
	  * @param applicationContext
	  * @throws BeansException
	  */
	  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
	      this.applicationContext = applicationContext;
	  }
	 
	  /**
	  * @return ApplicationContext
	  */
	  public static ApplicationContext getApplicationContext() {
	    return applicationContext;
	  }
	 
	 <span style="color:#cc0000;"> /**
	  * 获取对象  
	  * @param name
	  * @return Object 一个以所给名字注册的bean的实例
	  * @throws BeansException
	  */
	  public static Object getBean(String name) throws BeansException {
	    return applicationContext.getBean(name);
	  }
	 
	  /**
	  * 获取类型为requiredType的对象
	  * 如果bean不能被类型转换,相应的异常将会被抛出(BeanNotOfRequiredTypeException)
	  * @param name       bean注册名
	  * @param requiredType 返回对象类型
	  * @return Object 返回requiredType类型对象
	  * @throws BeansException
	  */
	  public static Object getBean(String name, Class requiredType) throws BeansException {
	    return applicationContext.getBean(name, requiredType);
	  }</span>
	 
	  /**
	  * 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
	  * @param name
	  * @return boolean
	  */
	  public static boolean containsBean(String name) {
	    return applicationContext.containsBean(name);
	  }
	 
	  /**
	  * 判断以给定名字注册的bean定义是一个singleton还是一个prototype。
	  * 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)  
	  * @param name
	  * @return boolean
	  * @throws NoSuchBeanDefinitionException
	  */
	  public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
	    return applicationContext.isSingleton(name);
	  }
	 
	  /**
	  * @param name
	  * @return Class 注册对象的类型
	  * @throws NoSuchBeanDefinitionException
	  */
	  public static Class getType(String name) throws NoSuchBeanDefinitionException {
	    return applicationContext.getType(name);
	  }
	 
	  /**
	  * 如果给定的bean名字在bean定义中有别名,则返回这些别名  
	  * @param name
	  * @return
	  * @throws NoSuchBeanDefinitionException
	  */
	  public static String[] getAliases(String name) throws NoSuchBeanDefinitionException {
	    return applicationContext.getAliases(name);
	  }
}


看到了applicationContext.getBean(name)的方法,就大致明白了。这个真的就只是Util类。是一个类里面,包含applicationContext,然后用applicationContext的方法。

那么,applicationContext是什么东东呢?

把鼠标放上去:




Objectorg.springframework.beans.factory.BeanFactory.getBean(String
name) throws BeansException


Return an instance, which may be shared or independent, of the specified bean.

This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern. Callers may retain references to returned objects in the case of Singleton beans.

Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.

Parameters:name the name of the bean to retrieveReturns:an instance of the beanThrows:NoSuchBeanDefinitionException - if there is no bean definition with the specified nameBeansException - if the bean could not be obtained

走下去:

再看源码就没必要了,都是接口,打开API里面搜索

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/ApplicationContext.html

All Superinterfaces,就看到了赫赫有名的beanfactory

All Superinterfaces:
ApplicationEventPublisher, BeanFactory, EnvironmentCapable, HierarchicalBeanFactory, ListableBeanFactory, MessageSource, ResourceLoader, ResourcePatternResolver

由于刚才已经显示,getBean这个方法,是BeanFactiory的,所以应该跑进去看BeanFactiory,光看此类是没有结果的。

所以进BeanFactiory

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/BeanFactory.html

<T> T
getBean(Class<T> requiredType)


Return the bean instance that uniquely matches the given object type, if any.
<T> T
getBean(Class<T> requiredType, Object... args)


Return an instance, which may be shared or independent, of the specified bean.
Object
getBean(String name)


Return an instance, which may be shared or independent, of the specified bean.
<T> T
getBean(String name, Class<T> requiredType)


Return an instance, which may be shared or independent, of the specified bean.
Object
getBean(String name, Object... args)


Return an instance, which may be shared or independent, of the specified bean.
出现的这几个方法,都是getBean相关。具体可以进去看方法。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:config/ctx-common.xml,
			classpath:config/ctx-uniQuery.xml,
			classpath:config/ctx-quartz.xml
		</param-value>
	</context-param>
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>/WEB-INF/classes/log4j.properties</param-value>
	</context-param>
	<context-param>
		<param-name>log4jRefreshInterval</param-name>
		<param-value>60000</param-value>
	</context-param>
	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<listener>
		<listener-class>
			org.springframework.web.util.IntrospectorCleanupListener
		</listener-class>
	</listener>
	
	<filter>  
        <filter-name>timetaskckfilefilter</filter-name>  
        <filter-class>com.umpay.hfmng.timetask.TimeTaskCKFileFilter</filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>timetaskckfilefilter</filter-name>  
        <url-pattern>/timetaskckfile/*</url-pattern>  
    </filter-mapping>  
    
	<filter>  
	    <filter-name>timetaskfeedbackfilter</filter-name>  
	    <filter-class>com.umpay.hfmng.timetask.TimeTaskFeedbackFilter</filter-class>  
    </filter>  
	<filter-mapping>  
	    <filter-name>timetaskfeedbackfilter</filter-name>  
	    <url-pattern>/timetaskfeedback/*</url-pattern>  
	</filter-mapping>  

	<servlet>
		<servlet-name>ssoLogoutServlet</servlet-name>
		<servlet-class>com.umpay.sso.client.SSOClientLogoutServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ssoLogoutServlet</servlet-name>
		<url-pattern>/ssoClient/logout</url-pattern>
	</servlet-mapping>
	
	<filter>
		<filter-name>encodingFilter</filter-name>
		<filter-class>
			org.springframework.web.filter.CharacterEncodingFilter
		</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>
	
	<filter>  
   		<filter-name>requestContextFilter</filter-name>  
    	<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>  
	</filter>
	<filter-mapping>  
    	<filter-name>requestContextFilter</filter-name>  
    	<url-pattern>/*</url-pattern>  
	</filter-mapping>

	<filter>
		<filter-name>SSOAgent</filter-name>
		<filter-class>com.umpay.sso.client.SSOAgent</filter-class>
		 <init-param>
			<param-name>_exclude_urlpattern</param-name>
			<param-value>.jpg|.css|.js|.jpg|.gif|.png|.gzjs|.gzcss|.htm</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>SSOAgent</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<filter>
		<filter-name>SSOUrlAclFilter</filter-name>
		<filter-class>com.umpay.sso.client.SSOUrlAclFilter</filter-class>
		 <init-param>
			<param-name>blackList</param-name>
			<param-value>/a/*.do*</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>*.html</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>*.htm</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>*.do</url-pattern>
	</filter-mapping>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>
	
	<filter-mapping>
		<filter-name>SSOUrlAclFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>
	
	<servlet>
		<servlet-name>busi</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:config/ctx-mvc.xml
			</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>

	
	<servlet-mapping>
		<servlet-name>busi</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
		
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<error-page>
		<error-code>403</error-code>
		<location>/jsp/sys/403.jsp</location>
	</error-page>
	<error-page>
		<error-code>404</error-code>
		<location>/jsp/sys/404.jsp</location>
	</error-page>
	<error-page>
		<error-code>500</error-code>
		<location>/jsp/sys/500.jsp</location>
	</error-page>

</web-app>


ctx-common.xml

<?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"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
            http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/spring-context-3.0.xsd  
            http://www.springframework.org/schema/tx  
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
            http://www.springframework.org/schema/jdbc  
            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"> 
	<!--messageSource -->
	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>classpath:messages</value>
			</list>
		</property>
		<property name="cacheSeconds">
			<value>10</value>
		</property>
	</bean>
	<!--system config -->
	<bean id="sysConfSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>classpath:sysconf</value>
			</list>
		</property>
		<property name="cacheSeconds">
			<value>10</value>
		</property>
	</bean>
	<bean id="messageService" class="com.umpay.hfmng.service.impl.MessageServiceImpl">
		<constructor-arg ref="messageSource" />
		<constructor-arg ref="sysConfSource" />
	</bean>

	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location">
			<value>classpath:jdbc.properties</value>
			<!-- <value>classpath:proxool.properties</value> -->
		</property>
	</bean>

	<!-- cache -->
	<bean id="cacheManager"
		class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<property name="configLocation">
			<value>classpath:ehcache.xml</value>
		</property>
	</bean>

	<bean id="CouponInfCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>CouponInfCache</value>
		</property>
	</bean>
	<bean id="ChannelInfoCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>ChannelInfoCache</value>
		</property>
	</bean>
	<bean id="MerInfoCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>MerInfoCache</value>
		</property>
	</bean>
	<bean id="GoodsTypeCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>GoodsTypeCache</value>
		</property>
	</bean>
	<bean id="BankInfoCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>BankInfoCache</value>
		</property>
	</bean>
	
	<bean id="XeBankInfoCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>XeBankInfoCache</value>
		</property>
	</bean>

	<bean id="GoodsInfoCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>GoodsInfoCache</value>
		</property>
	</bean>
	<bean id="UserInfoCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>UserInfoCache</value>
		</property>
	</bean>
	<bean id="OperCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>OperCache</value>
		</property>
	</bean>
	<bean id="UrlAclCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>UrlAclCache</value>
		</property>
	</bean>
	<bean id="UserRoleCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>UserRoleCache</value>
		</property>
	</bean>
	<bean id="ChnlInfCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>ChnlInfCache</value>
		</property>
	</bean>
	<bean id="SecMerInfCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>SecMerInfCache</value>
		</property>
	</bean>
	<bean id="GoodsCategoryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>GoodsCategoryCache</value>
		</property>
	</bean>
	<bean id="ParaCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>ParaCache</value>
		</property>
	</bean>
	<bean id="MerOperCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
		<property name="cacheManager">
			<ref local="cacheManager" />
		</property>
		<property name="cacheName">
			<value>MerOperCache</value>
		</property>
	</bean>
	<bean id="cacheMap" class="java.util.HashMap">
		<constructor-arg>
			<map>
				<entry key="CouponInfCache" value-ref="CouponInfCache" />
				<entry key="MerInfoCache" value-ref="MerInfoCache" />
				<entry key="BankInfoCache" value-ref="BankInfoCache" />
				<entry key="XeBankInfoCache" value-ref="XeBankInfoCache" />
				<entry key="GoodsInfoCache" value-ref="GoodsInfoCache" />
				<entry key="UserInfoCache" value-ref="UserInfoCache" />
				<entry key="OperCache" value-ref="OperCache" />
				<entry key="UrlAclCache" value-ref="UrlAclCache" />
				<entry key="GoodsTypeCache" value-ref="GoodsTypeCache" />
				<entry key="UserRoleCache" value-ref="UserRoleCache" />
				<entry key="ChannelInfoCache" value-ref="ChannelInfoCache" />
				<entry key="ChnlInfCache" value-ref="ChnlInfCache" />
				<entry key="SecMerInfCache" value-ref="SecMerInfCache" />
				<entry key="GoodsCategoryCache" value-ref="GoodsCategoryCache" />
				<entry key="ParaCache" value-ref="ParaCache" />
				<entry key="MerOperCache" value-ref="MerOperCache" />
			</map>
		</constructor-arg>
	</bean>
	<!-- <bean id="merInfoDao" class="com.umpay.hfmng.dao.impl.MerInfoDaoImpl"> 
		</bean> -->
	<bean id="HfCache" class="com.umpay.hfmng.cache.HfCache">
		<property name="cacheMp" ref="cacheMap" />
		<!-- <property name="merInfoDao" ref="merInfoDao"/> -->
		<property name="messageService" ref="messageService" />
	</bean>

	<!-- 数据源配置,使用应用内的C3P0数据库连接池 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${jdbc.driver}" />
		<property name="jdbcUrl" value="${jdbc.url}" />
		<property name="user" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="autoCommitOnClose" value="true" />
		<property name="checkoutTimeout" value="10000" /><!-- 10s -->
		<property name="initialPoolSize" value="1" />
		<property name="minPoolSize" value="1" />
		<property name="maxPoolSize" value="2" />
		<property name="acquireIncrement" value="1" />
		<property name="idleConnectionTestPeriod" value="60" /><!-- 60s -->
		<property name="preferredTestQuery" value="values(current timestamp)" />
	</bean>
	<!-- 事务管理器配置,单数据源事务 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation" value="classpath:sqlmap-config.xml" />
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean id="dao" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
		<property name="sqlMapClient" ref="sqlMapClient" />
	</bean>
	
	<!-- 离线库的连接池、sqlMapClient和dao -->
	<bean id="dataSourceOffline" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${offline.jdbc.driver}" />
		<property name="jdbcUrl" value="${offline.jdbc.url}" />
		<property name="user" value="${offline.jdbc.username}" />
		<property name="password" value="${offline.jdbc.password}" />
		<property name="autoCommitOnClose" value="true" />
		<property name="checkoutTimeout" value="10000" /><!-- 10s -->
		<property name="initialPoolSize" value="1" />
		<property name="minPoolSize" value="1" />
		<property name="maxPoolSize" value="2" />
		<property name="acquireIncrement" value="1" />
		<property name="idleConnectionTestPeriod" value="60" /><!-- 60s -->
		<property name="preferredTestQuery" value="values(current timestamp)" />
	</bean>
	<bean id="sqlMapClient_Offline" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation" value="classpath:sqlmap-config-offline.xml" />
		<property name="dataSource" ref="dataSourceOffline" />
	</bean>
	<bean id="offlineDao" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
		<property name="sqlMapClient" ref="sqlMapClient_Offline" />
	</bean>
	
	<!-- 使用annotation定义事务 <tx:annotation-driven transaction-manager="transactionManager" 
		/> -->
	<!-- 支持上传文件 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!--resolveLazily属性启用是为了推迟文件解析,以便在action中捕获文件大小异常 -->
		<property name="resolveLazily" value="true" />
		<!--最大为10M 即10*1024*1024bytes -->
		<property name="maxUploadSize" value="10485760" />
	</bean>
	
	<!-- 资源层和业务层的链接控制器 -->
	<bean id="httpClientControler" class="com.umpay.hfmng.common.HttpClientControler" destroy-method="destory">
   		<constructor-arg index="0"><value>20</value></constructor-arg>
        <constructor-arg index="1"><value>30000</value></constructor-arg>
    </bean>

</beans>


ctx-quartz.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <!--起动Bean-->   
 <bean id="hfmngJob" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
    <property name="globalJobListeners">     
   		<list>     
    		<ref bean="commonJobListener" />     
  		</list>     
  	</property> 
    <property name="triggers">   
        <list>   
            <ref bean="feeCodeCountJobTrigger"/>
            <ref bean="tradeGradeTrigger"/>
            <ref bean="reduceDataGradeTrigger"/>
            <ref bean="calculateGradeTrigger"/>
            <ref bean="gradeRankTrigger"/>
        </list>   
    </property>   
 </bean>
 <!--实际的工作Bean-->   
 <bean id="commonJobListener" class="com.umpay.hfmng.job.CommonJobListener"></bean>

 <bean id="feeCodeCountJob" class="com.umpay.hfmng.job.FeeCodeCountJob" ></bean>
 <bean id="tradeGradeJob" class="com.umpay.hfmng.job.TradeGradeJob" ></bean>
 <bean id="reduceDataGradeJob" class="com.umpay.hfmng.job.ReduceDataGradeJob" ></bean>
 <bean id="calculateGradeJob" class="com.umpay.hfmng.job.CalculateGradeJob" ></bean>
 <bean id="gradeRankJob" class="com.umpay.hfmng.job.GradeRankJob" ></bean>
 
 <!--jobBean用于设定启动时运用的Bean与方法-->
 <bean id="feeCodeCountJobDetail"  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
     <property name="targetObject">
        <ref  bean="feeCodeCountJob"/>
     </property>
     <property name="targetMethod">
         <value>doJob</value>
     </property>
 </bean>
 <bean id="tradeGradeJobDetail"  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
     <property name="targetObject">   
        <ref  bean="tradeGradeJob"/>
     </property>
     <property name="targetMethod">
         <value>doJob</value>
     </property>
 </bean>
 <bean id="reduceDataGradeJobDetail"  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
     <property name="targetObject">   
        <ref  bean="reduceDataGradeJob"/>
     </property>
     <property name="targetMethod">
         <value>doJob</value>
     </property>
 </bean>
 <bean id="calculateGradeJobDetail"  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
     <property name="targetObject">   
        <ref  bean="calculateGradeJob"/>
     </property>
     <property name="targetMethod">
         <value>doJob</value>
     </property>
 </bean>
 <bean id="gradeRankJobDetail"  class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
     <property name="targetObject">
        <ref  bean="gradeRankJob"/>
     </property> 
     <property name="targetMethod">
         <value>doJob</value>
     </property>
 </bean>
 <!--定时器设定起动频率&启动时间-->
 <bean id="feeCodeCountJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">   
 	<property  name="jobDetail">
 		<ref bean="feeCodeCountJobDetail"/>    
 	</property>   
 	<property name="cronExpression">
 		<value>0 0 01 * * ?</value>   
 		<!-- "0 0 01 * * ?" 每天一点触发-->  
	</property>   
 </bean>
 <bean id="tradeGradeTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
 	<property  name="jobDetail">
 		<ref bean="tradeGradeJobDetail"/>
 	</property>
 	<property name="cronExpression">
 		<value>15 12 5 3 * ?</value>     
	</property>
 </bean>
 <bean id="reduceDataGradeTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
 	<property  name="jobDetail">
 		<ref bean="reduceDataGradeJobDetail"/>
 	</property>
 	<property name="cronExpression">
 		<value>15 32 5 3 * ?</value>     
	</property>
 </bean>
 <bean id="calculateGradeTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
 	<property  name="jobDetail">
 		<ref bean="calculateGradeJobDetail"/>
 	</property>
 	<property name="cronExpression">
 		<value>15 52 5 3 * ?</value>     
	</property>
 </bean>
 <bean id="gradeRankTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
 	<property  name="jobDetail">
 		<ref bean="gradeRankJobDetail"/>
 	</property>
 	<property name="cronExpression">
 		<!-->value>15 2 2 26 * ?</value-->
 		<value>10 50 11 6 * ?</value>
	</property>
 </bean>
</beans>

ctx-uniQuery.xml

<?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"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
            http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 	<!-- 统一查询相关bean -->
	<bean id="namedJt" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
		<constructor-arg ref="dataSource" />   
	</bean>
	<bean id="uniQueryService" class="com.umpay.uniquery.impl.UniQueryServiceImpl">
		<property name="jt" ref="namedJt" />
		<property name="dialect" ref="db2Dialect" />
		<property name="sqlTemplate">  
			<ref bean="sqlTemplate" />
		</property>
	</bean>
	<bean id="db2Dialect" class="com.umpay.uniquery.impl.DB2Dialect">
	</bean>
	<bean id="sqlTemplate" class="com.umpay.uniquery.impl.VelocitySqlTemplate">  
		<property name="sqlConfig">  
			<ref bean="sqlConfig" />
		</property>
	</bean>
	
	<bean id="sqlConfig" class="com.umpay.uniquery.impl.XmlSqlConfig">
		<constructor-arg index="0" value="query" />
	</bean>
	<!-- 统一查询相关bean    离线库 -->
	<bean id="namedJtOffline" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
		<constructor-arg ref="dataSourceOffline" />   
	</bean>
	<bean id="uniQueryServiceOffline" class="com.umpay.uniquery.impl.UniQueryServiceImpl">
		<property name="jt" ref="namedJtOffline" />
		<property name="dialect" ref="db2Dialect" />
		<property name="sqlTemplate">  
			<ref bean="sqlTemplateOffline" />
		</property>
	</bean>
	<bean id="sqlTemplateOffline" class="com.umpay.uniquery.impl.VelocitySqlTemplate">  
		<property name="sqlConfig">  
			<ref bean="sqlConfigOffline" />
		</property>
	</bean>
	
	<bean id="sqlConfigOffline" class="com.umpay.uniquery.impl.XmlSqlConfig">
		<constructor-arg index="0" value="queryOffline" />
	</bean>
</beans>


ctx-mvc.xml

<?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"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
            http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-3.0.xsd             http://www.springframework.org/schema/aop             http://www.springframework.org/schema/aop/spring-aop-3.0.xsd             http://www.springframework.org/schema/tx  
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  ">
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
	<bean
		class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />

	<!-- spring视图展示处理,如excel下载,json格式输出等 -->
	<bean id="xmlViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
		<property name="order" value="1" />
		<property name="location" value="/WEB-INF/classes/config/ctx-views.xml" />
	</bean>
	<!-- spring视图 velocity模板处理 -->
	<bean id="velocityConfig"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="resourceLoaderPath" value="/WEB-INF/vm/" />
		<property name="velocityProperties">
			<props>
				<prop key="input.encoding">UTF-8</prop>
				<prop key="output.encoding">UTF-8</prop>
				<prop key="contentType">text/html;charset=UTF-8</prop>

			</props>
		</property>
	</bean>
	<bean id="velocityViewResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="cache" value="false" />
		<property name="suffix" value=".vm" />
		<property name="contentType" value="text/html;charset=UTF-8" />
		<!--property name="exposeSpringMacroHelpers" value="true" / -->
		<property name="exposeRequestAttributes" value="true" />
		<property name="requestContextAttribute" value="request" />
		<property name="numberToolAttribute" value="number" />
		<property name="dateToolAttribute" value="date" />
	</bean>
	<!-- 自动搜索@Controller标注的类 -->
	<context:component-scan base-package="com.umpay.hfmng" />
	<!-- 获取Spring Application上下文 -->
	<bean id="SpringContextUtil" class="com.umpay.hfmng.common.SpringContextUtil" />

	<!-- 使用annotation定义事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" />

	<bean
		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
		<property name="interceptors">
			<!-- 多个拦截器,顺序执行 -->
			<list>
				<ref bean="logInterceptor" />
			</list>
		</property>
	</bean>
	<bean id="logInterceptor" class="com.umpay.hfmng.interceptor.LogInterceptor" />
	<bean id="daoLogger" class="com.umpay.hfmng.interceptor.DaoLoggerInterceptor" />
	<bean name="daoLogProxy"
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<value>daoLogger</value>
			</list>
		</property>
		<property name="beanNames">
			<list>
				<value>*DaoImpl</value>
			</list>
		</property>
	</bean>
</beans>


ctx-views.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<bean name="jsonView" class="com.umpay.hfmng.view.AjaxJsonView">   
       	 <property name="contentType"><value>application/json;charset=UTF-8</value></property>   
    </bean>
	<bean name="excelView" class="com.umpay.hfmng.view.ExcelView">     
    </bean>
	<bean name="excelViewMer" class="com.umpay.hfmng.view.MerExcelView">     
	</bean>
	<bean name="excelViewMerBank" class="com.umpay.hfmng.view.MerBankExcelView">     
    </bean>
    <bean name="excelFeeCode" class="com.umpay.hfmng.view.FeeCodeExcel">     
	</bean>
	<bean name="excelFeeCodeUseQuery" class="com.umpay.hfmng.view.FeeCodeUseQueryExcel">     
	</bean>
	<bean name="excelViewGoodsFeeCodeAdd" class="com.umpay.hfmng.view.GoodsFeeCodeAddExcelView">     
	</bean>
	<bean name="excelViewGoodsFeeCodeManage" class="com.umpay.hfmng.view.GoodsFeeCodeManageExcelView">     
	</bean>
	<bean name="excelViewFeeCodeImportError" class="com.umpay.hfmng.view.FeeCodeImportErrorView">
	</bean>
	<bean name="excelStatsView" class="com.umpay.hfmng.view.ExcelCouponStatsView">
	</bean>
	<bean name="couponCodeExcelView" class="com.umpay.hfmng.view.CouponCodeExcelView">
	</bean>
	
	<bean name="bakeupDataView" class="com.umpay.hfmng.view.BakeupDataExcelView">
	</bean>
	
	<bean name="excelMerGrade" class="com.umpay.hfmng.view.MerGradeExcelView">
	</bean>
	<bean name="excelMerGradeImportError" class="com.umpay.hfmng.view.MerGradeImportErrorView">
	</bean>
	<bean name="excelDownloadDoc" class="com.umpay.hfmng.view.DownloadDocView">
	</bean>
	<bean name="excelChnlBank" class="com.umpay.hfmng.view.ChnlBankExcelView">
	</bean>
	<bean name="excelViewChnl" class="com.umpay.hfmng.view.ChnlExcelView">     
	</bean>
	<bean name="excelChnlGoods" class="com.umpay.hfmng.view.ChnlGoodsExcelView">     
	</bean>
	<bean name="excelChnlMer" class="com.umpay.hfmng.view.ChnlMerExcelView">     
	</bean>
	<bean name="excelViewSecMer" class="com.umpay.hfmng.view.SecMerExcelView"> </bean>    
	<bean name="textView" class="com.umpay.hfmng.view.TextView"> 
	</bean>
	<bean name="excelProxyOrder" class="com.umpay.hfmng.view.ProxyOrderExcelView"></bean>
	<bean name="excelMerBusiConf" class="com.umpay.hfmng.view.MerBusiConfView"></bean>
	<bean name="stlAllBillExcelView" class="com.umpay.hfmng.view.StlAllBillExcelView"></bean>
	<bean name="stlBjBillExcelView" class="com.umpay.hfmng.view.StlBjBillExcelView"></bean>
	<bean name="stlSwBillExcelView" class="com.umpay.hfmng.view.StlSwBillExcelView"></bean>
	<bean name="xlsView" class="com.umpay.hfmng.view.XlsView"></bean>
	<bean name="upServiceView" class="com.umpay.hfmng.view.UPServiceExcelView"></bean>
</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: