wicket1.3.5+spring2.5+hibernate3.2

   不喜欢Tapestry4要用hivemind,wicket与spring集成更简单些,刚接触wicket,学习下。
1.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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>wicket</display-name>
	
	<listener>    
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    
	</listener>
	
	<context-param>    
		<param-name>contextConfigLocation</param-name>    
		<param-value>classpath:applicationContext.xml</param-value>    
	</context-param>  
	
    <servlet>
	    <servlet-name>wicket</servlet-name>
	    <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
	    <init-param>
	        <param-name>applicationFactoryClassName</param-name>
	        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
	    </init-param>
	    <load-on-startup>1</load-on-startup>
	</servlet>
    <servlet-mapping>
		<servlet-name>wicket</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
    
</web-app>


2.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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
	<description>Wicket</description>
	<!-- dataSource for Oracle -->
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName"
			value="com.mysql.jdbc.Driver"/>
		<property name="url"
			value="jdbc:mysql://localhost:3306/wicket" />
		<property name="username" value="logcd" />
		<property name="password" value="****" />
	</bean>

	<!-- Hibernate SessionFactory for mysql -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />

		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:com/logcd/wicket/mapping/</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.jdbc.fetch_size">50</prop>
				<prop key="hibernate.jdbc.batch_size">100</prop>
			</props>
		</property>
	</bean>
	<!-- Hibernate SessionFactory for mysql -->

	<!-- Transaction -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<bean id="baseTransactionProxy" lazy-init="true" abstract="true"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="do*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	<!-- Transaction -->

	<!-- DAO -->
	<bean id="baseDao" lazy-init="true" abstract="true"
		class="com.logcd.common.bo.dao.impl.GenericDaoImpl">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
	</bean>
	
	<bean id="kingModulesDao" parent="baseDao" 
		class="com.logcd.web.bo.dao.impl.KingModulesDaoImpl">
	</bean>
	<!-- DAO -->

	<!--service-->
	<bean id="publicService" parent="baseTransactionProxy"> 
		<property name="target"> 
			<bean class="com.logcd.web.business.service.impl.PublicServiceImpl" autowire="byName"> 
			</bean> 
		</property> 
	</bean>
	<!--service-->
	<bean id="wicketApplication" class="com.logcd.wicket.lab.WicketApplication"/>

</beans>


3.WicketApplication.java
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import com.logcd.wicket.index.Index;

public class WicketApplication extends WebApplication {

	public WicketApplication() {
	}

	public void init() {
		super.init();
		addComponentInstantiationListener(new SpringComponentInjector(this));    
	}

	public Class getHomePage() {
		return Index.class;
	}
}

4.页面java中注入bean:类型不能为接口,用private  PublicService publicService要报错。
	@SpringBean(name="publicService")
	private PublicServiceImpl publicService;



附:wicketAjaxDebugEnable=false;//禁用Ajax调试
   Wicket 与通常的Web 程序有一点不同,就是它的运行状态分成开发模式(Development Mode)和部署模式(Deploy Mode)。
(1).web.xml
<param-name>configuration</param-name>
<param-value>DEPLOYMENT</param-value>

(2).是调用Application 这个基类中的configure 方法来改变当前的运行状态。
webApplica tion.configure(Application.DEVELOPMENT);
webApplica tion.configure(Application.DEPLOYMENT);

你可能感兴趣的:(spring,xml,Hibernate,tapestry,wicket)