jeeCmsV7-src 源码解析之二(application-context.xml)

<!--xml进入路径web.xml/application-context.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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"
	default-lazy-init="true">

	<!-- 加载数据库属性文件,以便动态获取 -->
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>/WEB-INF/config/jdbc.properties</value>
			</list>
		</property>
	</bean>
	<!-- 加载其它属性文件 -->
	<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="locations">
			<list>
				<!-- 其中包话数据库连接,hbm文件和连接池信息 -->
				<value>/WEB-INF/config/jdbc.properties</value>
				<!-- 暂时未知 -->
				<value>/WEB-INF/config/jeecms/jeecms.properties</value>
				<!-- 暂时未知 -->
				<value>/WEB-INF/config/plug/**/*.properties</value>
			</list>
		</property>
		<qualifier value="main"/>
	</bean>
	<!-- 通过PropertyUtils包操作properties属性文件中的属性,以便动态获取 -->
	<bean id="propertyUtils" class="com.jeecms.common.util.PropertyUtils">
		<property name="properties" ref="properties"/>
	</bean>
	<!-- 根据已加载的数据库属性文件,连接数据库 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc.url}" />
		<property name="user" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		 <!--连接关闭时默认将所有未提交的操作回滚。Default: false -->   
		<property name="autoCommitOnClose" value="true"/>
		 <!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,  
           	 超时后将抛出 SQLException,如设为0则无限期等待。单位毫秒。Default: 0 -->  
		<property name="checkoutTimeout" value="${cpool.checkoutTimeout}"/>
		<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> 
		<property name="initialPoolSize" value="${cpool.minPoolSize}"/>
		<!--连接池中保留的最小连接数。-->  
		<property name="minPoolSize" value="${cpool.minPoolSize}"/>
		<!--连接池中保留的最大连接数。Default: 15 --> 
		<property name="maxPoolSize" value="${cpool.maxPoolSize}"/>
		 <!--最大空闲时间,maxIdleTime秒内未使用则连 接被丢弃。若为0则永不丢弃。Default: 0 -->
		<property name="maxIdleTime" value="${cpool.maxIdleTime}"/>
		<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->   
		<property name="acquireIncrement" value="${cpool.acquireIncrement}"/>
		 <!--  
            default : 0 单位 s  
            这个配置主要是为了减轻连接池的负载,比如连接池中连接数因为某次数据访问高峰导致创建了很多数据连接  
            但是后面的时间段需要的数据库连接数很少,则此时连接池完全没有必要维护那么多的连接,所以有必要将  
            断开丢弃掉一些连接来减轻负载,必须小于maxIdleTime。配置不为0,则会将连接池中的连接数量保持到minPoolSize。  
            为0则不处理。   
         -->  
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}"/>
	</bean>
	<!-- 设置数据库session工厂 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<!-- 动态地通过properties文件加载映射的hbm文件 -->
		<property name="mappingLocations" value="#{propertyUtils.getList('hibernate.hbm')}"/>	
		<!-- 配置hibernate属性 -->
		<property name="hibernateProperties">
			<value>
			<!-- 指定数据库方言 --> 
			hibernate.dialect=${hibernate.dialect}
			<!-- 输出所有SQL语句到控制台 -->  
			hibernate.show_sql=false
			<!-- 格式化输出sql语句 --> 
			hibernate.format_sql=false
			 <!--   
                这个配置意思是当你在Hibernate里面输入true的时候,Hibernate会转化为0插入数据库,  
                当你在Hibernate里面输入false的时候,Hibernate会转化为1插入数据库,  
             --> 
			hibernate.query.substitutions=true 1, false 0
			<!-- 指定每次提交SQL的数量。参数值越大,读数据库的次数越少,速度越快。 --> 
			hibernate.jdbc.batch_size=20
			 <!--   
                允许查询缓存,对经常使用的List查询方式,只有在使用查询缓存时,  
                才会从缓存中通过id去get缓存的值;查询缓存一般缓存查询语句和查询结果的id --> 
			hibernate.cache.use_query_cache=true
			</value>
		</property>
		<property name="entityInterceptor">   
			<ref local="treeInterceptor"/>
		</property>
		<property name="cacheProvider">
			<ref local="cacheProvider"/>
		</property>
		<property name="lobHandler">
			<ref bean="lobHandler" />
		</property>
	</bean>
	<!-- 处理 LOB 数据,CLOB 类型,BLOB 类型 --> 
	<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/>
	<!-- 缓存 -->  
	<bean id="cacheProvider" class="com.jeecms.common.hibernate3.SpringEhCacheProvider">
		<property name="configLocation">
			<value>/WEB-INF/config/ehcache-hibernate.xml</value>
		</property>
		<property name="diskStoreLocation">
			<value>/WEB-INF/cache/hibernate</value>
		</property>
	</bean>
	<!-- 栏目等树形结构 -->
	<bean id="treeInterceptor" class="com.jeecms.common.hibernate3.TreeIntercptor"/>
	<!-- 定义事务管理器(声明式的事务) -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<!-- 是隐式地向 Spring 容器注入 -->  
	<context:annotation-config/>
	<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

这个错误表明在指定的路径下找不到名为`application-context.xml`的文件。可能有以下几个原因导致这个问题: 1. 文件路径不正确:请确保`application-context.xml`文件位于正确的路径下。默认情况下,Spring Boot会在`src/main/resources`目录下查找`application-context.xml`文件。如果你将该文件放在其他位置,请确保路径是正确的。 2. 资源文件未正确加载:如果你使用了Maven或Gradle作为构建工具,则需要将`application-context.xml`文件放在测试资源目录下。默认情况下,测试资源目录是`src/test/resources`。请检查文件是否位于正确的资源目录中。 3. 文件名错误:请确保文件名拼写正确且大小写匹配。注意区分大小写,文件名应该是`application-context.xml`,而不是其他类似的名称。 如果你确认文件位置和名称都是正确的,但仍然遇到这个错误,可以尝试以下解决方法: 1. 清理并重新构建项目:有时候由于缓存或构建问题,可能需要清理项目并重新构建一次。可以尝试使用构建工具的清理命令,如`mvn clean`或`gradle clean`,然后重新运行单元测试。 2. 检查依赖:请确保项目的依赖项已正确配置。检查是否有缺少的依赖或版本冲突导致无法加载`application-context.xml`文件。 3. 检查文件权限:如果你使用了特定的文件系统权限设置,确保单元测试能够访问和读取`application-context.xml`文件。 希望这些解决方法能帮助你解决问题!如果还有其他疑问,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值