tapestry4.0 &spring&hibernate3.0完全配置(servlet2.4)

3 篇文章 0 订阅
2 篇文章 0 订阅

相关基本配置文件
  web.xml
  hivemind.xml
  applicationContent.xml

1。 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>BadmintonClub</display-name>
 <filter>
   <filter-name>redirect</filter-name>
   <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
 </filter>
 <filter-mapping>
   <filter-name>redirect</filter-name>
      <url-pattern>/</url-pattern>
 </filter-mapping>
 
<!--*****************************-->
      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-

value>
     </context-param>
     <listener>
        <listener-class>
                org.springframework.web.context.ContextLoaderListener
        </listener-class>
     </listener>
<!--*****************************-->
     <servlet>
            <servlet-name>BadmintonClub</servlet-name>
            <servlet-class>
                   org.apache.tapestry.ApplicationServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
     </servlet>
    
     <servlet-mapping>
            <servlet-name>BadmintonClub</servlet-name>
            <url-pattern>/app</url-pattern>
     </servlet-mapping>
    
     <session-config>
            <session-timeout>15</session-timeout>
     </session-config>
</web-app>

其中
      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-

value>
     </context-param>
     <listener>
        <listener-class>
                org.springframework.web.context.ContextLoaderListener
        </listener-class>
     </listener>
为与spring相关

2。  hivemind.xml

<?xml version="1.0"?>
<module id="badminton" version="1.0.0">
  <contribution configuration-id="hivemind.ApplicationDefaults">
    <default symbol="hivemind.lib.spring-bean-factory" value="/service-

property:app.SpringContextFactory:appContext"/>
  </contribution>
    <service-point id="SpringContextFactory">       
        <invoke-factory>
            <construct class="SpringContextFactory">
                <set-service property="servletContext" service-

id="tapestry.globals.ServletContext"/>
            </construct>
        </invoke-factory>       
    </service-point>
</module>
其中类SpringContextFactory包名在projectname.application中指定。
    <meta key="org.apache.tapestry.page-class-packages"  value="

com.springAndTapestry"/>
SpringContextFactory
package com.springAndTapestry;

import javax.servlet.ServletContext;

import org.springframework.web.context.WebApplicationContext;
import

org.springframework.web.context.support.WebApplicationContextUtils;


public class SpringContextFactory {
    private ServletContext servletContext;
    private WebApplicationContext appContext;
   
    public WebApplicationContext getAppContext() {
        return appContext;
    }   
   
    public ServletContext getServletContext() {
        return servletContext;
    }

    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
        appContext =

WebApplicationContextUtils.getWebApplicationContext

(getServletContext());
    }    
}

3. applicationContext.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <bean id="dataSource"

class="org.apache.commons.dbcp.BasicDataSource" destroy-

method="close">
  <property name="driverClassName">
   <value>org.gjt.mm.mysql.Driver</value>
  </property>
  <property name="url">
   <value>jdbc:mysql://localhost:3306/erp</value>
  </property>
  <property name="username">
   <value>root</value>
  </property>
  <property name="password">
   <value></value>
  </property>
 </bean>

 <bean id="sessionFactory"
 

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="dataSource" />
  </property>
  <property name="mappingResources">
     <list>
      <value>CourtChoiceInfo.hbm.xml</value>
      <value>CourtLocation.hbm.xml</value>
      <value>MeterialInfo.hbm.xml</value>
      <value>UserInfo.hbm.xml</value>
        <value>User.hbm.xml</value>
    </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
 </bean>

  <bean id="utildao" class="com.sap.badminton.hibernate.dao.UtilDao">
       <property name="sessionFactory">
           <ref local="sessionFactory" />
       </property>
  </bean>
  <bean id="param" class="com.sap.badminton.common.Parameters">
     <property name="maxResult">
           <value>5</value>
     </property>
  </bean> 
</beans>


通过这三部,配置就完成了,然后可以在java类中通过Tapestry的

@InjectObject来注入在applicationContext.xml中定义的bean:
例·:Home.java

package com.springAndTapestry;

import lxh.hibernate.User;

import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.html.BasePage;

import com.sap.badminton.common.Parameters;
import com.sap.badminton.hibernate.dao.UtilDao;


public abstract class Home extends BasePage {
  @InjectObject("spring:param")
  public abstract Parameters getParam();
 
  public String getTest(){
  // return this.getParam().getMaxResult()+"" ;
   return this.getii();
  
  }
 
//注入UtilDao类
  @InjectObject("spring:utildao")
  public abstract UtilDao getUtilDao();
 
  public String getii(){
   UtilDao ud = this.getUtilDao() ;
   User user = new User() ;
   user.setId("6666XX") ;
   user.setPassword("888888") ;
   ud.save(user) ;
   System.out.println(ud.getSessionFactory());
   return "Hello xiaohongli" ;
  }

}

Home.page

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE page-specification PUBLIC
  "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
  "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">

<page-specification>
    <component id="test" type="Insert">
        <binding name="value" value="test"/>
    </component>
</page-specification>

Home.html

<span jwcid="test" />

这个测试已经成功,如果大家还有什么更好的方法,麻烦教我一下,谢谢

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值