Grails 2 では、XPlugin.groovy で Bean をオーバーライドすると、doWithSpring() メソッドでサービスを再定義する必要がありました。
def doWithSpring = {
tokenStorageService(TokenStorageProxyService) { it.autowire = 'byName' }
}
私は Grails 3 でプログラミングを開始し、すでに Grails 2 の経験があり、既存の Grails 2 プラグインのいくつかの Grails 3 バージョンを作成しているため、新しいプラグインで同じ種類のオーバーライドを試みました。
Closure doWithSpring() { {->
tokenStorageService(TokenStorageProxyService) {
it.autowire = 'byName'
}
} }
私はいくつかの統合テストを行いました:
@Integration
class SecurityServiceIntegrationSpec extends Specification {
SecurityService securityService
TokenStorageProxyService tokenStorageService
...
}
テストを実行すると、次のエラーが表示されます。
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'grails.plugin.springsecurity.rest.token.storage.jwt.JwtTokenStorageService' to required type 'com.b2boost.grails3.auth.client.TokenStorageProxyService' for property 'tokenStorageService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'grails.plugin.springsecurity.rest.token.storage.jwt.JwtTokenStorageService' to required type 'com.b2boost.grails3.auth.client.TokenStorageProxyService' for property 'tokenStorageService': no matching editors or conversion strategy found at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:605) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:400) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:119) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) ... at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalStateException: Cannot convert value of type 'grails.plugin.springsecurity.rest.token.storage.jwt.JwtTokenStorageService' to required type 'com.b2boost.grails3.auth.client.TokenStorageProxyService' for property 'tokenStorageService': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:306) at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590) ... 37 more
デフォルトの JwtTokenStorageService が TokenStorageProxyService によってオーバーライドされていないようで、サービスが統合テストに接続されているときに ConversionNotSupportedException が発生します。プラグインでサービスをオーバーライドするにはどうすればよいですか?