Struts2jar包和web.xml的配置
Struts2jar包的引入:
Struts——2.3.15\apps\Struts2-blank.war\WEB-INF\lib\*.jar
Struts——2.3.15\lib\Struts-json——plugin.jar
Struts——2.3.15\lib\Struts-sprint-plugin.jar
web.xml文件配置
<!-- 配置Struts核心过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
spring3jar包和web.xml配置
jar包引入:
Spring3.2 开发最基本jar包
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar
spring-expression-3.2.0.RELEASE.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
AOP开发
spring-aop-3.2.0.RELEASE.jar
spring-aspects-3.2.0.RELEASE.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
Spring Jdbc开发
spring-jdbc-3.2.0.RELEASE.jar
spring-tx-3.2.0.RELEASE.jar
Spring事务管理
spring-tx-3.2.0.RELEASE.jar
Spring整合其他ORM框架
spring-orm-3.2.0.RELEASE.jar
Spring在web中使用
spring-web-3.2.0.RELEASE.jar
Spring整合Junit测试
spring-test-3.2.0.RELEASE.jar
web.xml文件配置
<!-- 配置spring核心监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 全局参数 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
applicationContext.xml
log4j.properties
hibernate3jar包和web.xml配置
jar包引入:
hibernate-distribution3.6.10.final\hibernate3.jar
hibernate-distribution-3.6.10.Final\lib\required\*.jar
hibernate-distribution-3.6.10.Final\lib\jpa\*.jar
slf4j-log4j整合的jar包
数据库驱动:
连接池c3p0连接池
如果使用hibernate的二级缓存则引入二级缓存的jar包
配置文件:
可以去掉(配置到spring中),本项目中就是没有hibernate核心配置的整合
映射文件:需要在代码中完成。
3.配置基本信息在applicationContext.xml中:
c3p0连接池:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
事务管理:
<!-- 事务管理 -->
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
<!-- 开启注解事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</bean>
hibernate相关信息配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 注入连接池 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 配置hibernate其他设置 -->
<property name="hibernateProperties">
<props>
<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.connection.autocommit">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 配置映射hibernate映射文件 -->
</bean>
配置连接池:引入外部属性文件
<context:property-placeholder location="classpath:jdbc.properties"/>