spring常规配置

classpath :标示src目录


<!-- 定义受环境影响易变的变量 -->
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<!-- 标准配置 -->
				<value>classpath*:**/*.properties</value>
				<!-- 集群中节点配置 -->
				<!--value>classpath*:/application.cluster.properties</value-->
				<!-- 本地开发环境配置 -->
				<!-- value>classpath*:/application.local.properties</value-->
				<!-- 服务器生产环境配置 -->
				<!-- value>file:/var/springside/application.server.properties</value-->
			</list>
		</property>
	</bean>

		<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" 
				value="">
		</property>
		<property name="jdbcUrl"
				value="">
		</property>
		<property name="user" value=""></property>
		<property name="password" value=""></property>
		<property name="minPoolSize" value="5"></property>
		<property name="maxPoolSize" value="30"></property>
		<property name="initialPoolSize" value="10"></property>
		<property name="maxIdleTime" value="3000"></property>
		<property name="acquireIncrement" value="5"></property>
		<property name="maxStatements" value="0"></property>
		<property name="acquireRetryAttempts" value="30"></property>
		<property name="acquireRetryDelay" value="1000"></property>
		<property name="idleConnectionTestPeriod" value="18000"></property>
		<property name="checkoutTimeout" value="3000"></property>
	</bean>


	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					 方言定义
					<!-- org.hibernate.dialect.MySQLDialect -->
				</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
		<property name="mappingDirectoryLocations">
			<list>
				<!--实体路径 这里也可以定义保内搜索-->
				<value>classpath:/com/entity</value>
				 
			</list>
		</property>
		<property name="eventListeners" >
			<map>
			<!-- 
				<entry key="flush" value-ref="patchedFlushEventListener"></entry>
				
				<entry key="post-update" value-ref="logListener" />
				<entry key="post-insert" value-ref="logListener" />
				<entry key="post-delete" value-ref="logListener" />
				<entry key="pre-update" value-ref="lockListener"></entry> -->
			</map>
		</property> 
 
	</bean>



		<!--   内事务管理  -->
		<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
			<property name="sessionFactory" ref="sessionFactory"></property>
		</bean>	
		<tx:advice id="txAdvice" transaction-manager="transactionManager">
			<tx:attributes>
				<tx:method name="*" propagation="REQUIRED" />
				<tx:method name="get*" read-only="true"/>
				<tx:method name="find*" read-only="true"/>
			</tx:attributes>
		</tx:advice>
		
		<aop:config>
			<aop:advisor advice-ref="txAdvice" pointcut="execution(* * ..manager.*Manager.*(..))"/>
		</aop:config>



	
	<!-加载配置文件-->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>

	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>




	<!-- 配合hibernate的lazy(延时加载),必须配置在所有filter之前,否则不生效-->
	<filter>
		<filter-name>openSession</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
		<init-param>
			<param-name>singleSession</param-name>
			<param-value>true</param-value>
		</init-param>
		<init-param>
			<param-name>sessionFactoryBeanName</param-name>
			<param-value>sessionFactory</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>openSession</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-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>
	</filter>
	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

<beans xmlns="http://www.springframework.org/schema/beans"  
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">  
          <import resource="classpath:comt/user/application1.xml"/>  
        <import resource="classpath:com/test/application1.xml"/>  
   </beans>

 

猜你喜欢

转载自username2.iteye.com/blog/1669534