资产已被定义为对象的资产(Assets is already defined as object A

2019-08-19 00:05发布

:我在这里所描述做着玩子项目功能的更多扩展测试http://www.playframework.com/documentation/2.0/SBTSubProjects 。 但我得到的错误:

Assets is already defined as object Assets

托管在GitHub上的示例应用程序: https://github.com/adis-me/PlayStrap

我已经在此描述定义的资产控制器我子项目: 资产控制器的描述 ,甚至为主营项目,但错误不断弹出。 有什么不对我的项目?

调节器

package com.company.playstrap.controllers;

import controllers.AssetsBuilder;

public class Assets {

    public static controllers.AssetsBuilder delegate = new AssetsBuilder();

}

路线文件

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                               com.company.playstrap.controllers.Application.index()

# Include sub projects
-> /common                              common.Routes
-> /admin                               admin.Routes
-> /website                             website.Routes

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file                   com.company.playstrap.controllers.Assets.delegates.at(path="/public", file)

Answer 1:

这是一个已知的bug: https://groups.google.com/forum/#!msg/play-framework/2Zk5wjAlIng/Jcec1lt7AzQJ

我对自己的管理模块的解决方法:

package controllers.admin;
import controllers.AssetsBuilder;
import play.api.mvc.AnyContent;
import play.api.mvc.Action;
import play.mvc.*;

public class Application extends Controller {

    private static AssetsBuilder delegate = new AssetsBuilder();

    public static Action<AnyContent> asset(String path, String file) {
        return delegate.at(path, file);
    }

}

//routes file
GET /assets/*file   controllers.admin.Application.asset(path="/public", file)


Answer 2:

我上周面对这个问题时,我试图写的资产类作为一个Java类。 我可以解决这个问题汇编写在我的辅助模块中的资产类如Scala的类,在文档中描述的一样: http://www.playframework.com/documentation/2.1.1/SBTSubProjects

基本上,我的项目的结构是:

MyApplication
  | - app
  | - conf
  | - modules
        | - admin
            | - app
                | - controllers
                    | - admin
                        | - Assets.scala
  | - project
  | - public


Assets.scala内容:

package controllers.contabil

object Assets extends controllers.AssetsBuilder 


最后,我admin.routes文件的内容是:

GET     /assets/*file    controllers.admin.Assets.at(path="/public", file)

# Home page
GET     /index           controllers.admin.Application.index() 


干杯



文章来源: Assets is already defined as object Assets