您的位置:首页 > 其它

SSH框架整合配置文件模式2

2013-10-23 18:18 323 查看
web.xml文件的配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name>

<!-- 加载spring的配置文件 -->
<listener>
<listenerclass>org.springframework.web.context.ContextLoaderListene
</listener-class>
</listener>

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

<!-- 将session的范围开启到jsp页面 -->
<filter>
<filter-name>openSessionInView</filter-name>

<filter-class>

org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter </filter-class>

<init-param>

<param-name>entityManagerFactoryBeanName</param-name>

<param-value>entityManagerFactory</param-value>

</init-param>

</filter>

<!--filter的映射文件-->
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- 配置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>

<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>

<error-page>
<error-code>500</error-code>
<location>/500.jsp</location>
</error-page>
</web-app>

struts.xml文件的配置:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

<!-- 指定默认编码集 ,作用于HttpServletRequest的setCharacterEncoding()和freemarker,vilocity的输出 -->

<constant name="struts.i18n.encoding" value="UTF-8"/>
<!-- 设置浏览器是否缓存静态内容 ,默认值为true(生产环境下使用)开发阶段最好关闭 -->
<constant name="struts.serve.static.bowserCache" value="false"/>
<!-- 开发模式下打印详细的错误信息 -->
<constant name="struts.devMode" value="true"/>

<!-- 默认的试图主题 simple , xhtml ,css , ajax -->
<!-- 设置最大上传文件是30M -->

<constant name="struts.ui.theme" value="simple"/>
<!-- 设置默认的临时文件存储位置 -->
<constant name="struts.multipart.maxSize" value="31457280" />
<!--设置文件上传-->
<constant name="struts.multipart.saveDir" value="/fileUploadTemp" />

<!-- 包含配置信息文件 -->

<include file="XX/XX/struts.xx.xml"></include>
<!-- 验证码 action -->

<!--这儿也可以直接定义对应的Action文件,可省去包含文件-->

<package name="" namespace="/" extends="struts-default">
<action name="" class="xx.xx.Action"/>
<result name="">/xx.jsp</result>

</package>

<!--拦截器的定义-->

<interceptors>
<interceptor name="xxx" class="xxxInterceptor"></interceptor>
<interceptor-stack name="xx">
<interceptor-ref name=" xx"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>

<!-- 全局转发 -->
<global-results>
<result name="index" type="redirect">/index.jsp</result>
</global-results>

</struts>

jdbc.properties文件的配置

jdbc.driverClassName=com.mysql.jdbc.Driver

jdbc.url=jdbc\:mysql\://localhost\:3306/databaseName

jsbc.username=root

jdbc.password=root

##连接池启动时的初始值

jdbc.initalSize = 5

##连接池启动时的最大值

jdbc.maxActive = 10

##最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止
jdbc.maxIdle=3
## 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请
jdbc.minIdle=1

beans.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!--启动组件扫描-->
<context:component-scan base-package="cn.edu.pdsu"/>
<!--启动注解注入-->
<context:annotation-config />
<!--proxy-target-class="true"强制使用cglib代理 如果为false则spring会自动选择 -->
<aop:aspectj-autoproxy proxy-target-class="true" />

<!-- 配置数据源 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties" />
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 连接池启动时的初始值 -->
<property name="initialSize" value="${jdbc.initialSize}" />
<!-- 连接池的最大值 -->
<property name="maxActive" value="${jdbc.maxActive}" />
<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
<property name="maxIdle" value="${jdbc.maxIdle}" />
<!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
<property name="minIdle" value="${jdbc.minIdle}" />
</bean>

<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
<property name="persistenceUnitName" value="Unit" />
<property name="jpaProperties">
<props>
<prop key="javax.persistence.validation.mode">none</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.fetch_size">18</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>

</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<!-- 采用annotation的方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />

</beans>

persistence.xml配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="Unit" transaction-type="RESOURCE_LOCAL">

<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
</properties>
</persistence-unit>
</persistence>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: