tapestry4.0 &spring&hibernate3.0完全配置(servlet2.4)
2006-10-18 21:50
701 查看
相关基本配置文件
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" />
这个测试已经成功,如果大家还有什么更好的方法,麻烦教我一下,谢谢
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" />
这个测试已经成功,如果大家还有什么更好的方法,麻烦教我一下,谢谢
相关文章推荐
- jsp+servlet+javabean && struts+spring+hibernate
- Servlet, Spring, hibernate基本配置
- SpringMVC-Spring-Hibernate项目搭建之一-- 搭建maven 项目 & servlet的demo
- Spring 的 JMX 配置 (Hibernate & Ehcache 统计)
- File Templates for web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)
- Spring配置web.xml的<servlet>标签
- 告别繁琐的配置文件 ---- 全注解Spring,Hibernate开发 不完全指南
- JAVA SSH框架的配置(myeclipse(9)+tomcat(6.0.35)+struts(2.2.3)+Spring(3.0)+Hibernate(3.0))
- spring与servlet3.0无web.xml文件时的配置方式
- web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)
- UserDao找不到,框架集成,springMVC和hibernate和Spring 保错。tomcat保错。。UserDao 找不到在spring-servlet.xml配置
- web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)模板
- Servlet, Spring, hibernate基本配置
- web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)模板
- spring+springmvc+hibernate+freemark+redis完全注解配置
- hibernate3.0+ejb3 annotaion配置实战+spring1.21 annotation事务控制
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--配置文件
- File Templates for web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)
- spring 3.0 spring-servlet.xml配置 .
- hibernate3.0+ejb3 annotaion配置实战+spring1.21 annotation事务控制