0

I am trying out the ResourceProcessor interface in Spring Data REST. I don't think my Processor ever gets called. No error message either.

Here is my processor (in Groovy):

@Autowired
PersonService personService

@Override
public Resource<Person> process(Resource<Person> resource) {
    resource.content.isAdult = personService.isAdult(resource.content)

    // sanity check: does this link get added?? (NOPE!!)
    resource.add(new Link("http://localhost:8080/people", "added-link"))

    log.info "@@ resource.content.isAdult ==> ${resource.content}"

    return resource
}

Any help would be most appreciated!! You can see the entire project here in GitHub: https://github.com/txiasummer/spring-data-rest-examples

Tracy Xia
  • 371
  • 9
  • 22
  • Is your processor itself wired in, say, by being annotated with @Component? – Jason Aug 01 '15 at 09:04
  • Hi Jay! I am sorry, I just saw your comment. Yeah, the processor is annotated with Component... but I did not either manually declare it in Application.groovy as a Bean or enable ComponentScan. :( I just realized my mistake and fixed. I added ComponentScan to Application.groovy and now it is working as expected. Thank you so much for your comment! I wish I had seen it sooner--this has been driving me crazy for days. – Tracy Xia Aug 02 '15 at 17:00

1 Answers1

0

Finally got it to work! It turns out to be something completely trivial and I can't believe I missed it. I have a PersonProcessor classes which implements Spring's native ResourceProcessor interface. But PersonProcessor is still just a basic class that must be injected by Spring!! I think I was getting it confused with @Projection, which will be recognized automatically and does not need to be injected explicitly.

I addd @ComponentScan to my Application.groovy and now everything is working swimmingly. Alternatively, you an also manually define the PersonProcessor class and its service PersonService class as @Bean in Application.groovy. Again, you can see the whole project here: https://github.com/txiasummer/spring-data-rest-examples

Tracy Xia
  • 371
  • 9
  • 22