示例项目无法启动

时间:2017-12-12 11:28:05

标签: mysql spring-boot rethinkdb graphql-java

配置文件

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.example.demo.resolver.Mutation;
import com.example.demo.resolver.Query;

import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import static com.coxautodev.graphql.tools.SchemaParser.newParser;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private static Query query;

    @Autowired
    private static Mutation mutation;

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder;
    }

    @Autowired
    public GraphQL graphQL() {
        return GraphQL.newGraphQL(graphQLSchema())
                .build();
    }


    public static GraphQLSchema graphQLSchema(){
        return newParser()
                .file("schema.graphqls")
                .resolvers(query,mutation)
                .build()
                .makeExecutableSchema();
    }

}

Schema.graphqls

type User {
  uid: Long!
  name: String!
  password: String!
  address: String!
  mobile: Long!
}

type Query {
  allUsers: [User]
}

type Mutation {
  createUser(): User
}

schema {
  query: Query
  mutation: Mutation
}

错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webMvcConfig': Injection of autowired dependencies failed; nested exception is org.antlr.v4.runtime.misc.ParseCancellationException
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) [spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5170) [catalina.jar:8.0.27]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.27]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [catalina.jar:8.0.27]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [catalina.jar:8.0.27]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_144]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
    Caused by: org.antlr.v4.runtime.misc.ParseCancellationException: null
        at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:90) ~[antlr4-runtime-4.5.1.jar:4.5.1]
        at graphql.parser.antlr.GraphqlParser.name(GraphqlParser.java:1361) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.inputValueDefinition(GraphqlParser.java:3099) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.argumentsDefinition(GraphqlParser.java:3037) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.fieldDefinition(GraphqlParser.java:2965) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.objectTypeDefinition(GraphqlParser.java:2834) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.typeDefinition(GraphqlParser.java:2654) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.typeSystemDefinition(GraphqlParser.java:2437) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.definition(GraphqlParser.java:250) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.antlr.GraphqlParser.document(GraphqlParser.java:166) ~[graphql-java-3.0.0.jar:na]
        at graphql.parser.Parser.parseDocument(Parser.java:29) ~[graphql-java-3.0.0.jar:na]
        at com.coxautodev.graphql.tools.SchemaParserBuilder.build(SchemaParserBuilder.kt:101) ~[graphql-java-tools-3.2.0.jar:na]
        at com.example.demo.config.WebMvcConfig.graphQLSchema(WebMvcConfig.java:44) ~[classes/:0.0.1-SNAPSHOT]
        at com.example.demo.config.WebMvcConfig.graphQL(WebMvcConfig.java:35) ~[classes/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:701) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        ... 26 common frames omitted
    Caused by: org.antlr.v4.runtime.InputMismatchException: null
        at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:85) ~[antlr4-runtime-4.5.1.jar:4.5.1]
        ... 46 common frames omitted

1 个答案:

答案 0 :(得分:1)

如堆栈跟踪中所述,这是一个解析异常:

Caused by: org.antlr.v4.runtime.InputMismatchException: null =>这是相对于输入

Caused by: org.antlr.v4.runtime.misc.ParseCancellationException: null at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:90) ~[antlr4-runtime-4.5.1.jar:4.5.1] at graphql.parser.antlr.GraphqlParser.name(GraphqlParser.java:1361) ~[graphql-java-3.0.0.jar:na] at graphql.parser.antlr.GraphqlParser.inputValueDefinition(GraphqlParser.java:3099) ~[graphql-java-3.0.0.jar:na] at graphql.parser.antlr.GraphqlParser.argumentsDefinition(GraphqlParser.java:3037) ~[graphql-java-3.0.0.jar:na] at graphql.parser.antlr.GraphqlParser.fieldDefinition(GraphqlParser.java:2965) ~[graphql-java-3.0.0.jar:na] =>尝试解析输入名称时会引发异常

那有什么不对?在您的Mutation中,您声明了一个字段名createUser,并添加了括号:在GraphQL中,当使用括号时,这意味着您至少有输入/参数,输入必须采用<input name>: <input type>形式

删除括号,它应该有效; - )