配置spring4+spring mvc+hibernate4+hadoop1.2

打算做一个核心出来,用spring4+spring mvc+hibernate4+hadoop1.2,今天下午看了一下spring官方文档!然后百度了一下,终于把环境配置成功了

jar包特别的多,没有整理,全部都放进去了,因为这也是对hadoop1.2操作,所以呢,也有一些hadoop的jar包



第二呢,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>NetworkDisk</display-name>
 <!-- Spring 配置路径 -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <filter>
  <!-- 配置struts2拦截器 -->
  <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>
 
<!-- Spring的OpenSessionInView实现 -->
<filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<!-- singleSession默认为true,若设为false则等于没用OpenSessionInView 。所以默认可以不写-->
     <init-param>
       <param-name>singleSession</param-name>
       <param-value>true</param-value> 
     </init-param> 
<!-- 
指定org.springframework.orm.hibernate3.LocalSessionFactoryBean在spring配置文件中的名称,默认值为sessionFactory。 如果LocalSessionFactoryBean在spring中的名称不是sessionFactory,该参数一定要指定,否则会出现找不到sessionFactory的例外。所以默认可以不写
-->
 <init-param>
     <param-name>sessionFactoryBean</param-name>
   <param-value>sessionFactory</param-value>
  </init-param> 
</filter>
<filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
 

 <!-- 配置spring监听器 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <session-config>
  <session-timeout>1480</session-timeout>
 </session-config>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <error-page>
  <error-code>444</error-code>
  <location>/pageNotFund.jsp</location>
 </error-page>
 <error-page>
  <error-code>440</error-code>
  <location>/error.jsp</location>
 </error-page>
 
</web-app>

第三呢,struts2.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>


	<!-- struts.xml文件可以用include元素进行包含拆分后的struts的xml文件· -->
	<!--<include file="struts_war.xml"></include> -->
	<!-- 用constant元素可以代替struts.properties -->
	<constant name="struts.i18n.encoding" value="UTF-8"></constant>
	  <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
    <constant name="struts.configuration.xml.reload" value="true" />
	<!--下边这个常量信息有助于我们在开放过程中看到更多的出错信息 -->
	<constant name="struts.devMode" value="true"></constant>
	<!--下边这个常量信息是关于DMI即动态方法调用的常量,值必须为true才能实现动态方法调用 -->
	<constant name="struts.enable.DynamicMethodInvocation" value="true">
	</constant>
	<!-- 设置页面主题为simple -->
	<constant name="struts.ui.theme" value="simple" />

	<!-- 文件上传限制大小 -->
	<constant name="struts.multipart.maxSize" value="104857600000"></constant>


	<!-- 注册自己的文件上传解析类 -->
	<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest"
		name="requestParser" class="com.xun.disk.upload.listener.JakartaMultiPartRequest"
		scope="default" optional="true" />

	<constant name="struts.multipart.parser" value="requestParser" />
<!-- 验证码 -->
<package name="Security" namespace="/Security" extends="struts-default">
    <action name="SecurityCodeImageAction" 
    class="com.xun.disk.action.longin.SecurityCodeImageAction">
        <result name="success" type="stream">
            <param name="contentType">image/jpeg</param>
            <param name="inputName">imageStream</param>
            <param name="bufferSize">2048</param>
        </result>
    </action>
</package>
<!-- 文件上传  -->
<package name="edu" extends="struts-default">
		<action name ="fileUpload" class ="com.xun.disk.action.longin.FileAction" method="upload">
			<param name="savePath">/resources/files</param>
			<result name ="success">/result.jsp</result> <!--这个返回页面无所谓的,不刷新的 -->
        </action >
	</package>
	
<!-- 登录 -->
<package name="login" namespace="/" extends="struts-default">
   <action name="loginAction" class="com.xun.disk.action.longin.LoginAction" method="login">
      <result name="success">./disk.jsp</result>
       <result name="error">./login.jsp</result>
   </action>
   <action name="regionAction" class="com.xun.disk.action.longin.RegionAction" method="region">
      <result name="success">./disk.jsp</result>
       <result name="error">./login.jsp</result>
   </action>
   </package>
</struts>

然后就是core-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>
		<name>fs.default.name</name>
		<value>hdfs://192.168.117.2:9000</value>
	</property>
</configuration>

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>
	<!-- hibernate session工厂的名字 -->
	<session-factory name="test">
		<!-- JDBC配置 -->
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		
		<!-- 连接字符串默认编码为utf-8 -->
		<property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/disk?useUnicode=true&characterEncoding=utf-8</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">123456</property>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
		<!-- 选择update更新级别 -->
		<property name="hibernate.hbm2ddl.auto">update</property>
		<property name="hibernate.show_sql">true</property>
		<property name="hibernate.format_sql">true</property>


		<!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
		<property name="hibernate.c3p0.acquire_increment">5</property>
		<!-- 每60秒检查所有连接池中的空闲连接。Default: 0 -->
		<property name="hibernate.c3p0.idle_test_period">60</property>
		<!-- 连接池中保留的最大连接数。Default: 15 -->
		<property name="hibernate.c3p0.max_size">50</property>
		<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 
			如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
		<property name="hibernate.c3p0.max_statements">10</property>
		<!-- 连接池中保留的最小连接数 -->
		<property name="hibernate.c3p0.min_size">5</property>
		<!-- 当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出 SQLException,如设为0则无限期等待。单位毫秒。Default: 
			0 -->
		<property name="hibernate.c3p0.timeout">10000</property>
		<!-- 定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
		<property name="hibernate.c3p0.acquireRetryAttempts">30</property>
		<!-- 两次连接中间隔时间,单位毫秒。Default: 1000 -->
		<property name="hibernate.c3p0.acquireRetryDelay" >1000</property>

		<!-- 连接关闭时默认将所有未提交的操作回滚。Default: false -->
		<property name="hibernate.c3p0.autoCommitOnClose" >false</property>

		<!-- 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
		<property name="hibernate.c3p0.initialPoolSize"  >10</property>

		<!-- 最大空闲时间,600秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
		<property name="hibernate.c3p0.maxIdleTime" >600</property>
		<!-- c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么 属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试 
			使用。Default: null -->
		<property name="hibernate.c3p0.automaticTestTable" >TestTable</property>
		<!-- 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 
			获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
		<property name="hibernate.c3p0.breakAfterAcquireFailure"  >false</property>
		<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
		<property name="hibernate.c3p0.maxStatementsPerConnection">10</property>
		<!--c3p0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能 通过多线程实现多个操作同时被执行。Default: 
			3 -->
		<property name="hibernate.c3p0.numHelperThreads">10</property>
		<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校 验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable 
			等方法来提升连接测试的性能。Default: false -->
		<property name="hibernate.c3p0.testConnectionOnCheckout">false</property>
		<!--定义所有连接测试都执行的测试语句。在使用连接测试的情况下这个一显著提高测试速度。注意: 测试的表必须在初始数据源的时候就存在。Default: 
			null -->
		<property name="hibernate.c3p0.preferredTestQuery">select current_date as Systemtime;</property>


		<!-- 映射文件 -->
		<mapping resource="com/xun/disk/hibernate/entity/User.hbm.xml" />
		<!-- 映射文件  -->
		<mapping resource="com/xun/disk/hibernate/entity/Resource.hbm.xml" />
		<mapping resource="com/xun/disk/hibernate/entity/Admin.hbm.xml" />
		<mapping resource="com/xun/disk/hibernate/entity/Operation.hbm.xml" />
		<mapping resource="com/xun/disk/hibernate/entity/Audit.hbm.xml" />
		<mapping resource="com/xun/disk/hibernate/entity/Folder.hbm.xml" />
		<mapping
			resource="com/xun/disk/hibernate/entity/Resource_Folder.hbm.xml" />
	  
	</session-factory>
</hibernate-configuration>

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:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
		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-3.1.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">


	<!-- 这里使用import导入三个spring配置文件放置一个文件过大 -->
	<import resource="classpath:applicationContext-dao.xml" />
	<import resource="classpath:applicationContext-service.xml" />
	<import resource="classpath:applicationContext-action.xml" />

	<!-- 让Spring帮我们创建SessionFactory -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<!-- 告诉Hibernate配置文件在哪里 -->
		<property name="configLocation"
			value="classpath:hibernate.cfg.xml">
		</property>
	</bean>



	<!-- 让Spring来管理Hibernate事务的开启和关闭等
		1、事务管理器
		2、建立通知描述事务的特性
		3、装配起来
	-->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<!-- 因为事务由Session来创建,因而它需要知道用那个SessionFactory -->
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>



	<!-- 定义通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<!-- 定义事务的特性 -->
		<tx:attributes>
			<!-- 对于数据查找,我们不希望别人这个时间去修改数据 -->
			<tx:method name="get*" read-only="true" />
			<tx:method name="show*" read-only="true" />
			<!-- 对于数据修改我们必须放到一个事务中 -->
			<tx:method name="*"   propagation="REQUIRED"/>
		</tx:attributes>
	</tx:advice>


	<!-- 切面编程 -->
	<aop:config>

		<!-- 切入点 -->
		<aop:pointcut id="myBizOperation"
			expression="execution(* com.xun.disk.dao.*.*.*(..))" />
		<!-- 通知 -->
		<aop:advisor advice-ref="txAdvice"
			pointcut-ref="myBizOperation" />
	</aop:config>


	<bean class="com.xun.disk.hibernate.entity.User" id="user" scope="prototype"></bean>
	<!-- 创建实体类bean -->
	<bean  class="com.xun.disk.hibernate.entity.DfsOO" id="dfsOO" scope="prototype"></bean>
	<bean class="com.xun.disk.hibernate.entity.Admin" id="admin" scope="prototype"></bean>
	<bean class="com.xun.disk.hibernate.entity.Audit" id="audit" scope="prototype"></bean>
	<bean class="com.xun.disk.hibernate.entity.Operation" id="operation" scope="prototype"></bean>
	<bean class="com.xun.disk.hibernate.entity.Resource" id="resource" scope="prototype"></bean>

    <bean class="com.xun.disk.hibernate.entity.Folder" id="folder" scope="prototype"></bean>
    <bean class="com.xun.disk.hibernate.entity.FileUploadStatus" id="fileUploadStatus" scope="prototype"></bean>
    <bean class="com.xun.disk.hibernate.entity.Resource_Folder" id="resource_Folder" scope="prototype"></bean>

</beans>



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值