---
title: "Java在各种框架下编译Scala 【六】"
author: "keriny"
date: "2011-02-15T10:12:06Z"
tags: []
categories: ["编程语言"]
slug: "java-scala"
draft: false
lastmod: "2011-02-15T10:12:06Z"
id: 906456
url: "https://keriny.iteye.com/blog/906456"
---

**创建entity程序**

创建entity程序并将其映射到数据库：

```

package com.foo.myapp           
           
import javax.persistence.{GeneratedValue, Id, Entity}           
           
@Entity           
class Product {           
  @Id           
  @GeneratedValue           
  var id: Long = _           
  var name: String = _           
  var price: Double = _           
}           
 
```

**创建Wicket的应用程序**

最后，创建在同一个MyApp的Scala程序：

```

package com.foo.myapp           
           
 import org.apache.wicket.protocol.http.WebApplication          
importcom.ttdev.wicketpagetest.MockableSpringBeanInjector           
           
           
class MyApp extends WebApplication {           
  def getHomePage = classOf[MyPage]           
           
   override def init = {          
    MockableSpringBeanInjector.installInjector(this)           
           
  }           
}           
 
```

在这里，您指定为首页我的目录，植入Spring Bean中。

**运行应用程序**

随着IntelliJ IDEA的版本不断改进，您将嵌入到应用服务器运行您的应用程序。这非常容易，在刚刚创建的测试com.foo.myapp的ManualTest在刚刚创建的测试com.foo.myapp包一类ManualTest/scala文件（不是main/scala文件），以下内容是：

```

package com.foo.myapp           
           
importcom.ttdev.wicketpagetest.{WebAppJettyConfiguration, WicketAppJettyLauncher}           
           
           
object ManualTest {           
  def main(args: Array[String]) {           
    val l = new WicketAppJettyLauncher           
    l.startAppInJetty(new WebAppJettyConfiguration)           
  }           
}           
 
```

要运行的应用程序，首先需要运行数据库服务器上的H2程序。所以，在http://www.h2database.com下载和解压。然后变成h2/bin和运行h2.bat（或在Linux上h2.sh）。ManualTest是在IDEA的编辑器上，在IDEA选择运行DEA。它将运行ManualTest，Jetty的运行您的应用程序。

为了测试它，请尝试通过在浏览器http://localhost:8888/app。

不知道各位感觉如何。感谢各位支持！谢谢！

原文地址：agileskills2.org/blog/2010/06/19/getting-started-with-scala-spring-hibernate-wicket/

原文名：Getting started with Scala, Spring, Hibernate & Wicket

 

 

转载自：[http://developer.51cto.com/](http://developer.51cto.com/)