web.xml:
配置拦截器,app文件源位置,日志。
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>yourappname.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContextManager.xml
/WEB-INF/applicationContextDAO.xml </param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
<listener>
<listener-class> org.springframework.web.util.Log4jConfigListener </listenerclass>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContextManager.xml
/WEB-INF/applicationContextDAO.xml </param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
<listener>
<listener-class> org.springframework.web.util.Log4jConfigListener </listenerclass>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
配置延迟关闭hibernatesession:
<filter>
<filter-name>opensession</filter-name>
<filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>avensSessionFactory</param-value> </init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
spring-servlet.xml:
配置延迟关闭hibernatesession:
<filter>
<filter-name>opensession</filter-name>
<filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>avensSessionFactory</param-value> </init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>/.jsp</url-pattern>
</filter-mapping>
spring-servlet.xml:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView">
</property>
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.do">helloController</prop>
<prop key="/systemParameter.do">systemParameterController</prop>
</props>
</property>
</bean>
<!-- 设置action默认执行的方法 -->
<bean id="paraMethodResolver"
class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName">
<value>mn</value>
</property>
<property name="defaultMethodName">
<value>init</value>
</property>
</bean>
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">errors/error</prop>
</props>
</property>
<property name="exceptionAttribute" value="ex"></property>
<!-- 默认错误页面,当找不到上面mappings中指定的异常对应视图时,使用本默认配置 -->
<property name="defaultErrorView" value="errors/error"></property>
<!-- 默认HTTP状态码 -->
<property name="defaultStatusCode" value="500"></property>
</bean>
<!-- 文件上传配置 -->
<bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>30000000</value>
</property>
<property name="defaultEncoding" value="gbk"></property>
</bean>
applicationContextManager.xml:内容略去
applicationContextDAO.xml:
<bean id="helloController"
class="com.sinosoftech.jcywxt.controller.HelloController">
<property name="methodNameResolver" ref="paraMethodResolver"></property>
<property name="ysxxManager" ref="ysxxManager"></property>
</bean>
<bean id="systemParameterController" class="com.sinosoftech.jcywxt.controller.qxz.SystemParameterController">
<property name="methodNameResolver" ref="paraMethodResolver"></property>
<property name="systemParameterManager" ref="systemParameterManager"></property>
</bean>
applicationContextManager.xml:内容略去
applicationContextDAO.xml:
<!--数据库连接参数 -->
<bean id="ddbcPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- <property name="location" value="jdbc.properties"/> -->
<property name="locations" >
<list>
<value>/WEB-INF/jdbc.properties</value>
<value>/WEB-INF/archive.jdbc.properties</value>
</list>
</property>
</bean>
<!-- 数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- class文件在jar包中使用下面方法 -->
<property name="mappingLocations">
<list>
<value>classpath:/com/wdh/persistence/hibernate/*.hbm.xml</value>
</list>
</property>
<!-- 直接引用源文件使用下面方法 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/abc/</value>
<value>classpath:/com/wdh/hibernate/mapping/</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">false</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">60</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*DAO</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="ysxxDAO" class="com.sinosoftech.jcywxt.dao.qxz.impl.YsxxDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="systemParameterDAO" class="com.sinosoftech.jcywxt.dao.qxz.impl.SystemParameterDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>