在学习了一些教程之后,我想建立自己的与 Akka 聊天来玩一点。为了让事情变得更加困难,我也在尝试使用 IntelliJ IDEA 以及经过几年的 Eclipse。
我设置了一个简单的 POM 来获取 akka-cluster,启用自动导入并设置 IDEA 以支持 Scala(通过右键单击项目并在“框架支持”下启用 Scala);我已经写了几行代码来开始工作。奇怪的是,当代码编译并正确运行(打印“hello, world”并退出)时,IDEA 报告我的代码有问题(我预计会导致编译失败的错误)。
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>akka-chat-sim</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.4</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.3.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-cluster_2.10</artifactId>
<version>2.3.7</version>
</dependency>
</dependencies>
</project>
这是代码:
package com.example.tutorials.akka.chat
import akka.actor.{Props, ActorLogging, Actor, ActorSystem}
class Foo extends Actor with ActorLogging {
def receive = {
case s: String => {
log.info(s)
context.system.shutdown()
}
}
}
object Main extends App {
val system = ActorSystem("foo")
val foo = system.actorOf(Props[Foo], "foo")
foo ! "hello, world"
}
IntelliJ IDEA 说 ActorSystem 导入是未使用的(尽管它被使用了),并且在几行之后它说它无法解析 ActorSystem.apply (尽管它确实如此,因为它可以正确编译和运行)。
此外,它突出显示了 Foo 的接收方法的右大括号,告诉我Expression of type Unit doesn't conform to expected type BoxedUnit
.
我错过了什么?非常感谢你。