1

I want to inject a Spring Data JpaRepository into a goodle cloud endpoint class. How can I do this? Because I think currentliy the cloud endpoint class is not under Spring control and the autowired annotated repository remains always to null.

Some one found a solution for guice Appengine with Google Cloud Endpoints and Guice

What I want to do is the Same with Spring. So I want to bring up the cloud endpoints with the spring context.

Currently I do it over the Spring context to get my repositories like:

@Api(name = "myapi", version = "v1", scopes = { Constants.EMAIL_SCOPE }, clientIds = {
    Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID,
    Constants.IOS_CLIENT_ID, Constants.API_EXPLORER_CLIENT_ID }, audiences = {
Constants.ANDROID_AUDIENCE })
public class TestServiceImpl {

// @Autowired
private TestRepository repository;

public TestServiceImpl () {
    repository = ApplicationContextProvider.getApplicationContext()
            .getBean(TestRepository.class);

}

    ....
    }

But I want to use Autowired, is that possible?

Community
  • 1
  • 1
flosk8
  • 465
  • 1
  • 6
  • 17

1 Answers1

1

I encountered the same problem today. I found the solution by adding the following constructor:

public TestServiceImpl() {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}

Hope it helps.

ielkhalloufi
  • 652
  • 1
  • 10
  • 27
  • what does your web.xml look like? I get a exception in GAE Console.Uncaught exception from servlet javax.servlet.UnavailableException: java.lang.reflect.InvocationTargetException at org.mortbay.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:415) at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:458) – Jeryl Cook Feb 18 '16 at 14:00