I m trying to create a unit test for a service class that uses a constructor argument. I have already configured an entry in the grails-app/conf/spring/resources.groovy to allow Spring to create the bean using the constructor argument.
Running an integration test for the service class works without problem, however, running a unit test that uses @TestFor, the following exception shows up:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name sampleService : Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ph.jojopad.SampleService]: No default constructor found; nested exception is java.lang.NoSuchMethodException: ph.jojopad.SampleService.<init>()
at grails.test.mixin.services.ServiceUnitTestMixin.mockService(ServiceUnitTestMixin.groovy:54)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [ph.jojopad.SampleService]: No default constructor found; nested exception is java.lang.NoSuchMethodException: ph.jojopad.SampleService.<init>()
Caused by: java.lang.NoSuchMethodException: ph.jojopad.SampleService.<init>()
看来,“......选择”只期望一个使用违约构造的灯。 看看Grails I的文献,看不出任何关于如何使用@For for beans和有建筑论者的说法。 我期望,有了正确的铁路组合,即铁路-应用/组合/资源。 干.会.。