をプレイしていない私は、次のGroovyクラスがあります。Guiceの、Groovyの、@Canonicalと継承一緒にうまく
enum Protocol {
File,
Ftp,
Sftp,
Http,
Https
}
@Canonical
abstract class Endpoint {
String name
Protocol protocol
}
@Canonical
@TupleConstructor(includeFields=true, includeSuperFields=true)
class LocalEndpoint extends Endpoint {
}
class MyAppModule extends AbstractModule {
@Override
protected void configure() {
// Lots of stuff...
}
// Lots of other custom providers
@Provides
Endpoint providesEndpoint() {
new LocalEndpoint('fileystem', Protocol.File)
}
}
を私はちょうどEndpoint
の代わりにカスタムプロバイダーを使用している理由を心配しないでください。
bind(Endpoint).toInstance(new LocalEndpoint('fileystem', Protocol.File))
99.999%はこの問題の範囲外であり、完全な(非常に大きい)コードがどのように配線されているかによってコード化されています。
私の問題は、Guiceの、および/またはGroovyのはString
とProtocol
引数を取るLocalEndpoint
のコンストラクタを見つけることができないということです。
1) Error in custom provider, groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.example.myapp.model.LocalEndpoint(java.lang.String, com.example.myapp.model.Protocol)
at com.example.myapp.inject.MyAppModule.providesEndpoint(MyAppModule.groovy:130)
while locating com.example.myapp.model.Endpoint
for parameter 2 at com.example.myapp.inject.MyAppModule.providesConfig(MyAppModule.groovy:98)
at com.example.myapp.inject.MyAppModule.providesConfig(MyAppModule.groovy:98)
while locating com.example.myapp.config.MyAppConfig
それはその後、原因として以下の上場を持つ大規模なスタックトレースを出してくれる。
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.example.myapp.model.LocalEndpoint(java.lang.String, com.example.myapp.model.Protocol)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1731)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1534)
うまくいけば、これはおそらく、私はにいくつかの特別なパラメータを渡す必要があり、私はEndpoint
および/またはLocalEndpoint
を変更することで微調整ができるものです/@TupleConstructor
注釈などです。何か案は?
予選コンストラクタ内のパラメータnew LocalEndpoint(name: 'fileystem'、protocol:Protocol.File) –
ありがとう@ToddWCrone(+1)ですが、Groovyマップコンストラクタが嫌いです。 '@ Canonical'、' @ TupleConstructor'などのおかげで、通常の "Javaスタイル"のコンストラクタ呼び出しを使用できるはずです。どのようにこのsansマップのコンストラクタを取得するための任意の提案?再度、感謝します! – smeeb
修飾されたパラメータ名はより良いIMOです。より曖昧なコンストラクタを動作させるために多くの努力を払うつもりはありません。ごめんなさい。 –