applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 扫描注解 -->
<context:component-scan base-package="com.lanou"></context:component-scan>
<!-- 读取配置文件 -->
<context:property-placeholder location="classpath*:*.properties" />
<!-- 数据源 druid -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.loginName}"></property>
<property name="password" value="${jdbc.pwd}"></property>
<property name="driverClassName" value="${jdbc.driver}"></property>
</bean>
<!-- 会话工程 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- hibernate 属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.current_session_context_class">${hibernate.session}</prop>
</props>
</property>
<!-- 扫描实体映射文件 -->
<property name="mappingLocations">
<list>
<value>classpath:com/lanou/entity/*.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置hibernate4事物管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
jdbc.properties
# dataSource key=value
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/house
jdbc.loginName=root
jdbc.pwd=root
# hibernate
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.session=org.springframework.orm.hibernate4.SpringSessionContext
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 value="UTF-8" name="struts.i18n.encoding" />
<!-- 请求后缀 -->
<constant value="do,action" name="struts.action.extension" />
<!-- 热部署加载struts.xml文件 -->
<constant value="true" name="struts.configuration.xml.reload" />
<!-- 开发模式 -->
<constant value="true" name="struts.devMode" />
<package name="default" namespace="/" extends="struts-default,json-default">
<action name="index" class="indexAction" method="index">
<result name="success" type="redirect">
index.jsp
</result>
</action>
<action name="list" class="indexAction" method="houseList">
<result name="success" type="json">
<!-- list 在indexaction 一定一个属性 -->
<param name="root">list</param>
</result>
</action>
<action name="delect" class="indexAction" method="delectHouse">
<result name="success" type="redirect">
index.jsp
</result>
</action>
</package>
</struts>