2

I need to test rest api and need to access repository beans and service beans that are behind controllers in my Spring we application. How do I access them? Using JMX is it possible?

AccountRepository accountRepository = getBean(austin, AccountRepository.class);

protected SpringServerResource austin;

public <T> T getBean(SpringServerResource resource, String beanName, Class<T> beanType) {
        return resource.getServer().getContext().getBean(beanName, beanType);
    }
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
Julie
  • 179
  • 2
  • 13
  • Can you be more precise? Are you writing automated tests for your controller? Why do you want to access the service and the repository? – Gustavo Passini Jun 11 '19 at 00:28
  • Yes, I am writing automated tests. I want to be able to retrieve repository bean and assert on the entity. Also, if there are quartz scheduler jobs that run and don't have controllers, then I can get hold of the service beans and do asserts on those. Even if there are controllers some get and post are not exposed. In those cases as well, it would make sense to get the service bean or repo bean and use them to do asserts – Julie Jun 11 '19 at 19:11
  • Is you rest-api in the same project as of the repository beans? Is the rest-api part of same spring application? – Shubham Kadlag Jun 12 '19 at 03:38
  • yes, all running in one jvm – Julie Jun 13 '19 at 03:08

0 Answers0