日期:2014-05-16  浏览次数:20945 次

apache-wicket 学习笔记(一) maven依赖与集成spring
apache-wicket 学习笔记(一) maven依赖与集成spring

一) 官方网站发布的新消息wicket6.0已经发布了,上一个版本是1.5。可见官方直接升级了主版本号。
<dependency>
	<groupId>org.apache.wicket</groupId>
	<artifactId>wicket-core</artifactId>
	<version>6.0.0</version>
</dependency>
<dependency>
	<groupId>org.apache.wicket</groupId>
	<artifactId>wicket-extensions</artifactId>
	<version>6.0.0</version>
</dependency>
<dependency>
	<groupId>org.apache.wicket</groupId>
	<artifactId>wicket-auth-roles</artifactId>
	<version>6.0.0</version>
</dependency>
<dependency>
	<groupId>org.apache.wicket</groupId>
	<artifactId>wicket-spring</artifactId>
	<version>6.0.0</version>
</dependency>

spring嘛,在spring3.2还没有正式发布之前还是先用3.1或者2.5,个人觉得如果不用spring-mvc的话,2.5还是挺好用的。要加的依赖jar也只有一个。
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
</dependency>

或者
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-test</artifactId>
	<version>3.1.2.RELEASE</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-context-support</artifactId>
	<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-web</artifactId>
	<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
	<groupId>aopalliance</groupId>
	<artifactId>aopalliance</artifactId>
	<version>1.0</version>
</dependency>
<dependency>
	<groupId>org.aspectj</groupId>
	<artifactId>aspectjweaver</artifactId>
	<version>1.6.11</version>
</dependency>


二) 配置spring容器
在web.xml中用监听器,每个spring的web项目都要这么做。
<listener>
	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>classpath:spring-beans.xml</param-value>
</context-param>


三) wicket框架的核心组件是一个servlet
web.xml 被注释掉的部分在正式部署上线的时候一定要记得不注释符号去掉。
<servlet>
	<servlet-name>Application</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>
	<init-param>
		<param-name>applicationBean</param-name>
		<param-value>wicketApplication</param-value>
	</init-param>
	<!--
	<init-param>
		<param-name>configuration</param-name>
		<param-value>DEPLOYMENT</param-value>
	</init-param>
	-->
	<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>Application</servlet-name>
	<url-pattern>/*</url-pattern>
</servlet-mapping>


四) wicketApplication Bean 要加入代码。
package com.ztgame.webapp.wicket;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.springframework.stereotype.Component;

import com.ztgame