Has anyone sucessfully used the `JsonViewTest` tra...
# questions
p
Has anyone sucessfully used the
JsonViewTest
trait in the
views-json
plugin? My project uses this during integration tests but (Grails 4) it's now throwing an error:
Copy code
Unsatisfied dependency expressed through field 'grails_plugin_json_view_test_JsonViewTest__messageSource'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.context.MessageSource' available: expected single matching bean but found 2: messageSource,io.micronaut.spring.context.MicronautApplicationContext(Secondary)
The
JsonViewTest
trait does indeed have:
Copy code
@Autowired(required = false)
MessageSource messageSource = new StaticMessageSource()
Anyone else come across this?
In case anyone else comes across this; I think this is actually covered in the documentation (my fault for not reading it thoroughly...). The solution is to add
org.grails:views-json-testing-support:{version}
dependency and then implement in the test class using
JsonViewUnitTest
instead of
JsonViewTest
.
...and using
JsonViewUnitTest
breaks dependency injection for
ApplicationTagLib
and
AssetsTagLib
.
My final solution was to take a copy of the
JsonViewTest
code into my own trait and replace the
messageSource
DI with my own, 'manually' obtained instance at runtime (in the test).