SSH框架整合

来源:互联网 发布:pwm控制软件 编辑:程序博客网 时间:2024/05/21 13:54

applicationContext.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: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-2.5.xsd                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">    <!-- 自动扫描与装配bean -->    <context:component-scan base-package="cn.itcast.oa"></context:component-scan>    <!-- 导入外部的properties文件 -->    <context:property-placeholder location="classpath:jdbc.properties"/>        <!-- 配置SessionFactory -->    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    <!--指定hibernate配置文件路径 -->    <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>    <!--配置数据库连接池 -->    <property name="dataSource">            <bean class="com.mchange.v2.c3p0.ComboPooledDataSource">                <!-- 数据连接信息 -->                <property name="jdbcUrl" value="${jdbcUrl}"></property>                <property name="driverClass" value="${driverClass}"></property>                <property name="user" value="${user}"></property>                <property name="password" value="${password}"></property>                <!-- 其他配置 -->                <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->                <property name="initialPoolSize" value="3"></property>                <!--连接池中保留的最小连接数。Default: 3 -->                <property name="minPoolSize" value="3"></property>                <!--连接池中保留的最大连接数。Default: 15 -->                <property name="maxPoolSize" value="5"></property>                <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->                <property name="acquireIncrement" value="3"></property>                <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->                <property name="maxStatements" value="8"></property>                <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->                <property name="maxStatementsPerConnection" value="5"></property>                <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->                <property name="maxIdleTime" value="1800"></property>            </bean>    </property>    </bean>    <!-- 配置声明式事务管理(采用注解的方式) --><bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="txManager"><property name="sessionFactory" ref="sessionFactory"/></bean><tx:annotation-driven transaction-manager="txManager"/></beans>

hibernate.cfg.xml文件内容如下:

<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory>    <!-- 配置数据库连接 -->    <!--        <property name="connection.driver_class">com.jdbc.mysql.Driver</property>        <property name="connection.url">jdbc:mysql://localhost:3306/itcastoa0720</property>        <property name="connection.username">root</property>        <property name="connection.password">123</property>    -->    <!-- JDBC connection pool (use the built-in) -->    <property name="connection.pool_size">1</property>    <!-- SQL 方言 -->    <property name="dialect">        org.hibernate.dialect.MySQL5InnoDBDialect    </property>    <!-- Disable the second-level cache  -->    <property name="cache.provider_class">        org.hibernate.cache.NoCacheProvider    </property>    <!-- Echo all executed SQL to stdout -->    <property name="show_sql">true</property>    <!-- Drop and re-create the database schema on startup -->    <property name="hbm2ddl.auto">create</property>    <!-- Names the annotated entity class -->    <mapping resource="cn/itcast/oa/domain/User.hbm.xml" />    <mapping resource="cn/itcast/oa/domain/Role.hbm.xml" /></session-factory></hibernate-configuration>

struts.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <!-- 配置为开发模式 -->    <constant name="struts.enable.DynamicMethodInvocation" value="false" />    <constant name="struts.devMode" value="true" />    <!-- 把扩展名设置为action -->    <constant name="struts.action.extension" value="action" />    <!-- 把主题设置为simple -->    <constant name="struts.ui.theme" value="simple" />    <include file="example.xml"/>    <package name="default" namespace="/" extends="struts-default">      <!-- 配置测试用的ACTION(没有整合spring),class写类的全称(cn.itcast.oa.test.TestAction)-->      <!-- structs与spring整合结束以后我们可以用bean的名称来写class -->      <action name="test" class="testAction">      <result name="success">/test.jsp</result>      </action>      <!-- 岗位管理 -->      <action name="role_*" class="roleAction" method="{1}">          <result name="list">/WEB-INF/JSP/roleAction/list.jsp</result>          <result name="addUI">/WEB-INF/JSP/roleAction/addUI.jsp</result>          <result name="editUI">/WEB-INF/JSP/roleAction/editUI.jsp</result>          <result name="toList" type="redirectAction">role_list</result>      </action>    </package>    <!-- Add packages here --></struts>

jdbc.properties配置如下:

jdbcUrl     =jdbc:mysql://localhost:3306/itcastoa0720driverClass =com.mysql.jdbc.Driveruser        =rootpassword    =123

log4j.properties配置如下:

### direct log messages to stdout ###log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### direct messages to file hibernate.log ####log4j.appender.file=org.apache.log4j.FileAppender#log4j.appender.file.File=hibernate.log#log4j.appender.file.layout=org.apache.log4j.PatternLayout#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n### set log levels - for more verbose logging change 'info' to 'debug' ###log4j.rootLogger=error, stdout#log4j.logger.org.hibernate=infolog4j.logger.cn.itcast.oa=debug### log HQL query parser activity#log4j.logger.org.hibernate.hql.ast.AST=debug### log just the SQL#log4j.logger.org.hibernate.SQL=debug### log JDBC bind parameters ####log4j.logger.org.hibernate.type=info#log4j.logger.org.hibernate.type=debug### log schema export/update ####Slog4j.logger.org.hibernate.tool.hbm2ddl=debug### log HQL parse trees#log4j.logger.org.hibernate.hql=debug### log cache activity ####log4j.logger.org.hibernate.cache=debug### log transaction activity#log4j.logger.org.hibernate.transaction=debug### log JDBC resource acquisition#log4j.logger.org.hibernate.jdbc=debug### enable the following line if you want to track down connection ###### leakages when using DriverManagerConnectionProvider ####log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace

Custom.hbm.xml配置文件:

<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><hibernate-mapping default-lazy="false">    <class name="org.hibernate.test.legacy.Custom" persister="org.hibernate.test.legacy.CustomPersister">        <id type="string" name="id" column="id_" length="64" unsaved-value="null">            <generator class="uuid.hex"/>        </id>    </class></hibernate-mapping>

web.xml文件的内容如下:

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5"     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_2_5.xsd">    <!--配置spring的用于初始化容器对象的监听器-->    <listener>     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener><context-param>  <param-name>contextConfigLocation</param-name>  <param-value>/WEB-INF/applicationContext-*.xml,classpath:applicationContext*.xml</param-value></context-param>    <!-- 配置过滤器   -->    <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>  <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>
0 0
原创粉丝点击