SSH框架简单配置文件

(1)spring.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" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation=
	"http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx.xsd
	http://www.springframework.org/schema/context 
	http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd">
    
    <!-- 配置自动代理 -->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
    <!-- 自动扫描 -->
    <context:component-scan base-package="com.phome"></context:component-scan>
    <!-- 以注解方式注入bean的属性 -->
    <context:annotation-config></context:annotation-config>
    
    <!-- 配置数据源 -->
    <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<!-- 数据库驱动 -->
		<property name="driverClass" value="com.mysql.jdbc.Driver" />
		<!-- 数据库连接串 -->
		<property name="jdbcUrl" value="jdbc:mysql://localhost/test" />
		<!-- 数据库用户 -->
		<property name="user" value="root" />
		<!-- 数据库密码 -->
		<property name="password" value="root" />
		<!-- 最小连接数 -->
		<property name="minPoolSize" value="10" />
		<!-- 最大连接数 -->
		<property name="maxPoolSize" value="20" />
		<!-- 最大空闲的时间,单位是秒,无用的链接再过时后会被回收 -->
		<property name="maxIdleTime" value="1800" />
		<!-- 数据库连接池初始化时获取的连接数 -->
		<property name="initialPoolSize" value="2" />
		<!-- 在当前连接数耗尽的时候,一次获取的新的连接数 -->
		<property name="acquireIncrement" value="2" />
		<!-- 每隔1800S检查数据库空闲连接 -->
		<property name="idleConnectionTestPeriod" value="1800" />
		<!-- 当数据库连接失败以后尝试 重新连接的次数 -->
		<property name="acquireRetryAttempts" value="30" />
		<!-- 性能消耗较大,判断是否对每个获取的连接进行校验是否有效 -->
		<!-- 建议使用idleConnectoinTestPeriod和automaticTestTable来提升测试性能,默认:false -->
		<!-- <property name="testConnectionOnCheckout" value="false" /> -->
		<!-- JDBC标准参数,用来控制数据源内加载的PreparedStatement对象的数量 但是由于缓存的statement是属于单个Connection的而不是整个连接池的,所以这项配置需要考虑多方面的因素 
			如果maxStatement和maxStatementPerConnection都为0,则缓存关闭,模式:0 -->
		<!-- <property name="maxStatements" value="0" /> -->
		<!-- 对连接池的一种保护机制,当获取连接失败时会引起所有等待连接池来获取连接的线程抛出异常 但是数据源仍然有效保留,并在下次调用getConnection时继续重新尝试获取连接 
			如果设置为true,那么在尝试获取连接失败后,该数据源将申明已断开并永久关闭;默认:false -->
		<!-- <property name="breakAfterAcquireFailure" value="true" /> -->
	</bean>
	<!-- 配置sessionFactory对象,使用spring的sessionFactory对象 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<!-- 配置数据源 -->
		<property name="dataSource" ref="c3p0DataSource"></property>
		<!-- 配置hibernate常用属性 -->
		<property name="hibernateProperties">
			<value>
				hibernate.dialect=org.hibernate.dialect.MySQLDialect
				hibernate.hbm2ddl.auto=create
				hibernate.show_sql=true
				hibernate.format_sql=true
				hibernate.current_session_context_class=thread
			</value>
		</property>
		<!-- 配置映射文件 -->
		<property name="mappingResources">
			<value>com/phome/model/User.hbm.xml</value>
		</property>
	</bean>
	<!-- 配置事务管理器 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- 配置事务的注解支持 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
	
	<!-- 配置DAO对象 -->
	<bean id="userDAO" class="com.phome.dao.UserDAO">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- 配置service对象 -->
	<bean id="userService" class="com.phome.service.UserService">
		<property name="userDAO" ref="userDAO"></property>
	</bean>
    </beans>

(2)struts2.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">
	<struts>
		<constant name="struts.devMode" value="true"></constant>
	<constant name="struts.action.extension" value="action,do,,"></constant>
	
	<!-- 设置:让spring负责创建Action;将struts工厂要创建的对象,托管给spring工厂进行创建 -->
	<constant name="struts.objectFactory" value="spring"></constant>
	
	<package name="admin" extends="struts-default" namespace="/admin">
		<action name="login" class="com.phome.action.LoginAction">
			<result>/success.jsp</result>
		</action>
	</package>
	</struts>

(3)web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" 
version="3.0">
  <display-name>hibernate_1003_project_SSH</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!-- 监听器启动spring -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>/WEB-INF/spring/spring.xml</param-value>
  </context-param>
  
  <!-- 过滤器启动struts -->
  <filter>
  	<filter-name>struts2</filter-name>
  	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  	<init-param>
  		<param-name>config</param-name>
  		<param-value>
  			struts-default.xml,
				struts-plugin.xml,
				../struts/struts2.xml
  		</param-value>
  	</init-param>
  </filter>
  <filter-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
  </web-app>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值