No qualifying bean of type 'javax.persistence.EntityManager' available: expected single matching bean but found 2
You have defined two entitymanager. Now you have to tell spring which one should injected. For this you can use the @Qualifier
Annotation:
@PersistenceContext(unitName = "company")
@Qualifier(<Name of the entitimanager you want to use>)
private EntityManager entityManager;
Found a solution by marking the class I was injecting with the EntityManager with @Component and then auto-wiring that class into the class that uses the GraphQLExecutor:
New class marked @Component
package p4;
import org.crygier.graphql.GraphQLExecutor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Component
public class CompanyGraphQLComponent {
@PersistenceContext(unitName = "company")
private EntityManager entityManager;
public GraphQLExecutor graphQLExecutor() {
return new GraphQLExecutor(entityManager);
}
}
Class auto-wiring CompanyGraphQLComponent
package p4.rest.controllers;
import core_services.persistence.CompanyContextHolder;
import core_services.records.system.Company;
import graphql.ExecutionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import p4.CompanyGraphQLComponent;
import p4.records.GraphQLQuery;
@RestController
public class GraphQLController {
@Autowired
private CompanyGraphQLComponent companyGraphQLComponent;
@RequestMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_VALUE)
public ExecutionResult postJson(@RequestBody GraphQLQuery graphQLQuery) {
return companyGraphQLComponent.graphQLExecutor().execute(graphQLQuery.getQuery(), graphQLQuery.getVariables());
}
}