我有一个单身类课程,其中我在构造函数中注入了ConfigurationProvider类。
class Global {
ConfigurationProvider configurationProvider;
@Inject
Global(ConfigurationProvider configurationProvider){
this.configurationProvider = configurationProvider;
DatabaseConfiguration.DB_URL = configurationProvider.get().getConfig("db").getString("default.url");
}
}
当我尝试访问ConfigurationProvider类方法时,当我以测试生产模式开始时,对象不可用并抛出NullPoInterException(Activator TestProd(
我已经在模块类中融合了全球类
public class Module extends AbstractModule
{
@Override
public void configure()
{
// Use the system clock as the default implementation of Clock
bind(Clock.class).toInstance(Clock.systemDefaultZone());
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(ApplicationTimer.class).asEagerSingleton();
// Set AtomicCounter as the implementation for Counter.
bind(Counter.class).to(AtomicCounter.class);
bind(Global.class).in(Singleton.class);
}
}
您需要启用通过添加
创建的模块play.modules.enabled ="模块"
在您的 application.conf 文件中。因此,将配置依赖关系绑定。