将 Scala 模块添加到现有 Java 项目
所以我有一个相当大的Play!使用标准 Java 的项目。我想开始使用 Scala,并认为我可以将两者结合起来。我安装了 scala 模块并添加了配置行。然后我添加了一个新的控制器,如下所示:
package controllers
import play.mvc._
object Blog extends Controller {
def index = "test"
}
但是当我重新启动服务器并尝试浏览到 http://localhost:9000 /Blog/index 我收到“Blog.index 操作未找到”
是否需要执行其他操作来向此项目添加 Scala 支持,或者我必须从一开始就使用 Scala 创建一个新项目并复制所有项目文件?
更新
路线:
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET /explorer Application.index
GET /signup Application.signUp
POST /register Application.register
GET /tour Main.tour
GET / Main.homePage
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
* /admin module:crud
# Catch all
* / module:secure
* /{controller}/{action} {controller}.{action}
日志:
@65kk1d8dn
Blog.index action not found
Action not found
Action Blog.index could not be found. Error raised is Controller controllers.Blog not found
play.exceptions.ActionNotFoundException: Action Blog.index not found
at play.mvc.ActionInvoker.getActionMethod(ActionInvoker.java:447)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:78)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.Exception: Controller controllers.Blog not found
... 3 more
So I have a rather large Play! project using the standard Java stuff. I want to start using Scala and thought I could combine the two. I installed the scala module and added the config line. I then added a new controller like so:
package controllers
import play.mvc._
object Blog extends Controller {
def index = "test"
}
But when i restart the server and try to browse to http://localhost:9000/Blog/index i get "Blog.index action not found"
Is there something else I need to do to add Scala support to this project or must I create a new project with Scala from the get go and copy over all the files?
UPDATE
routes:
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET /explorer Application.index
GET /signup Application.signUp
POST /register Application.register
GET /tour Main.tour
GET / Main.homePage
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
* /admin module:crud
# Catch all
* / module:secure
* /{controller}/{action} {controller}.{action}
logs:
@65kk1d8dn
Blog.index action not found
Action not found
Action Blog.index could not be found. Error raised is Controller controllers.Blog not found
play.exceptions.ActionNotFoundException: Action Blog.index not found
at play.mvc.ActionInvoker.getActionMethod(ActionInvoker.java:447)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:78)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.Exception: Controller controllers.Blog not found
... 3 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你检查过路由文件吗?它包含到您的控制器/操作的路线?服务器启动时是否没有任何错误?
在我看来,路由文件中存在错误,您可以添加您的配置和您看到的完整错误消息吗?
编辑(添加路由后):
mm恐怕你的问题是Windows(我知道你上面的评论有明显的答案)。我在 Play Google 群组中看到了一些问题,全部与 Windows 相关。由于 Scala 支持在某种程度上仍然有点“实验性”,我只是相信你踩到了一个错误。我会与 Play 团队创建一张票证。
did you check the routes file? It contains the route to your controller/action? And is the server starting without any error?
It seems to me an error in routes file, could you add your config and the full error message you are seeing?
EDIT(after routes added):
mm I'm afraid your problem is Windows (obvious answer from your comment above, I know). I've seen a few issues in the Play Google group, all related to Windows. As Scala support is still a bit "experimental" to a certain degree, I just believe you stomped on a bug. I would create a ticket with the Play team.
因为,无论出于何种原因*,它都不是
Blog.index
,而是Blog$.index()
。Because, for whatever reason*, it's not
Blog.index
, it'sBlog$.index()
.