初级S2SH配置文件

1。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的文件 -->

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config/applicationContext.xml</param-value>
</context-param>

<!-- 配置struts2 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 实现spring 的监听 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<welcome-file-list>
<welcome-file>denglu.jsp</welcome-file>
</welcome-file-list>
</web-app>


2。 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:aop="http://www.springframework.org/schema/aop"
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.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
>




<!-- 配置sessionFacotry-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 加载hibernate.cfg.xml配置文件 -->
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>

</bean>



<!-- 配置一个HibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property><!-- 把sessionFactory工厂注入到模板 -->
</bean>
<!-- hibernateTemplate事务事务管理 jdbc:"org.springframework.jdbc.datasource.DataSourceTransactionManager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 配置哪些方法是要通过事务来管理 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

<aop:config>
<!-- 定义一个切入点 -->
<aop:pointcut id="mypointcut" expression="execution(* cn.com.kxrj.manager.impl.*.*(..)))"/>
<aop:advisor pointcut-ref="mypointcut" advice-ref="txAdvice"/>
</aop:config>
<!-- 启用AspectJ的支持 这里一定要写,-->
<aop:aspectj-autoproxy />


<!-- 数据库 -->

<bean id="template" abstract="true" lazy-init="default">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="baseDAO" class="cn.com.kxrj.tool.impl.BaseDAOImpl">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>

<bean id="studentDAO" class="cn.com.kxrj.dao.impl.StudentDAOImpl" parent="template">
</bean>

<!-- Manager -->
<bean id="studentManager" class="cn.com.kxrj.manager.impl.StudentManagerImpl">
<property name="studentDAO" ref="studentDAO"></property>
</bean>

<!-- action -->
<bean id="studentAction" class="cn.com.kxrj.action.StudentAction">
<property name="studentManager" ref="studentManager"></property>
</bean>
</beans>


3.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.multipart.maxSize" value="10701096" />
<constant name="struts.objectFactory" value="spring" />

<!-- 国际化处理,处理中文乱码-->
<constant name="struts.custom.i18n.resources"
value="messageResources" />
<constant name="struts.custom.i18n.encoding" value="utf-8" />
<constant name="struts.devMode" value="false" />
<package name="background" extends="struts-default" namespace="/background">
<!-- 学生 -->
<action name ="student" class="studentAction">
<result name="student_list">
/jsp/background/member/student_list.jsp
</result>
<result name="success">
/jsp/background/member/success.jsp
</result>
</action>


</package>
</struts>


4.hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>

<!-- JDBC connection pool (use the built-in)数据库连接池 -->
<property name="connection.pool_size">20</property>

<!-- SQL dialect数据库方言(我是使用的是oracle方言) -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</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">false</property>
<property name="format_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>



<!-- **********************学生************************ -->
<mapping resource="cn/com/kxrj/model/Student.hbm.xml"/>



</session-factory>

</hibernate-configuration>


5.Student.hbm.xml"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.kxrj.model">
<class name="Student" table="tb_student">
<id name="studentId" type="integer">
<column name="id"/>
<generator class="native"/>
</id>
<property name="studentName" type="string"
column="stuname" not-null="true" length="200"/>
<property name="studentPassword" type="string"
column="stupassword" not-null="true" length="30"/>
<property name="sex" type="string"
column="sex" not-null="true" length="20"/>
<property name="banji" type="string"
column="banji" not-null="true" length="100"/>
</class>
</hibernate-mapping>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值