Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing domain objects from external grails project - Method on class [] was used outside of a Grails applications

I have two Grails Projects in Eclipse. I am referencing one project inside the other with the Configure Build Path setup. Running tests however throws an error java.lang.IllegalStateException: Method on class [com.example.domain.Phone] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.

Normally this is fixed with a @Mock (using Mockito) or mockDomain(), but I am not in a unit test so these items are not seen.

How can I test my service layer through an integration test if it cannot see my domain objects that I need to use? These domain objects are separated because of the need to use them across multiple projects.

like image 430
bdparrish Avatar asked Sep 30 '22 03:09

bdparrish


1 Answers

If your GORM classes are not in the same package as your Application class then you need to add the ComponentScan annotation to the Application class to indicate where you GORM classes are. Example:

@ComponentScan(basePackages=['foo.bar', 'my.company'])
class Application {
....
like image 156
Graeme Rocher Avatar answered Oct 04 '22 20:10

Graeme Rocher