05-SSH综合案例:环境搭建之配置文件的引入
1.3 第三步导入相应配置文件
Struts框架中:
* web.xml
* 核心过滤器:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-name>
</filter>
<filter-mapping>
<filter-name>struts2</filter>
<url-pattern>/*</url-pattern>
</filter-mapping>
* struts.xml
Spring框架中:
*web.xml
        <!-- Spring框架使用监听器,服务器启动的时候加载Spring的配置文件 -->
        <listener>
               <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <!-- 监听器默认加载WEB-INF/application.xml-->
        <context-param>
               <param-name>contextConfigLocation</param-name>
               <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
* applicationContext.xml
<!-- 引入jdbc.properties文件-->
	<context:property-placeholder location="classpath:jdbc.properties"/>
	
	<!-- 配置连接池的信息-->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
	<!-- 数据库连接的四个基本参数   -->
		<property name="driverClass" value="${jdbc.driver}"/>  <!-- 驱动名称 -->
		<property name="jdbcUrl" value="${jdbc.url}"/>
		<property name="user" value="${jdbc.user}"/>
		<property name="password" value="${jdbc.password}"/>
	</bean>
	
	<!-- 配置Hibernate的相关属性  -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
			<!-- 注入连接池   现在由sessionFactory来维护我们的连接池-->
			<property name="dataSource" ref="dataSource"/>
<!-- 配置Hibernate的其他的属性 -->
					<property name="hibernateProperties">
			<props>
			    <!-- Hibernate的方言 -->
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.connection.autocommit">false</prop>
			</props>
		</property>
			
	</bean>
<!-- 声明式事务管理器 -->
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- 注入sessionFactory  因为我们的连接池已经交由sessionFactory来管理了 -->
     <property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 真正的管理事务  使用注解或者AOP 注解的话你哪个地方有事务一加一个@Transactional就可以了 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>
* 不使用hibernate配置文件:
* 将hibernate的信息配置到spring框架中.
Log4j的配置文件:
连接数据库基本参数配置文件:
Ctrl+Shift+T 查找类文件
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号