我在项目中使用 Wildfly 和 graphql-java 。我在教程中设置了像they这样的GraphQL端点,它与虚拟数据完美配合。但我无法注入我在Bean内部的Repository连接到我的数据库。注入的变量始终为空。
有人可以帮助我并告诉我我做错了什么吗?
GraphQLEndpoint
@WebServlet(urlPatterns = "/graphql")
public class GraphQLEndpoint extends SimpleGraphQLServlet {
@EJB()
private static CountRepositoryInterface countRepository;
public GraphQLEndpoint() {
super(buildSchema());
}
private static GraphQLSchema buildSchema() {
LinkRepository linkRepository = new LinkRepository(); // Dummy Data from ArrayList
TraceRepository traceRepository = new TraceRepository(); // Dummy Data from ArrayList
return SchemaParser.newParser()
.file("schema.graphqls")
.resolvers(new Query(linkRepository, traceRepository, countRepository))
.build()
.makeExecutableSchema();
}
}
CountRepositoryInterface
@Remote
public interface CountRepositoryInterface {
void createCounter(Counter counter);
Counter getCounterByUser(String userName);
void updateCounter(String userName);
void deleteAllCounter();
List<Counter> GetAllFromCounter();
}
CountRepository
@Stateless
public class CountRepository implements CountRepositoryInterface {
@PersistenceContext(unitName = "count")
private EntityManager entityManager;
public void createCounter(Counter counter) {
entityManager.persist(counter);
}
public List<Counter> GetAllFromCounter() {
Query query = entityManager.createQuery("SELECT c FROM Counter c");
return query.getResultList();
}
答案 0 :(得分:0)