当前位置: 首页 > 知识库问答 >
问题:

示例项目无法启动

蓬思博
2023-03-14

配置文件

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();
    }

}

模式。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个答案

郭瀚海
2023-03-14

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

原因:org。安特尔。v4。运行时。输入不匹配异常:null=

原因:org。安特尔。v4。运行时。杂项。ParseCancellationException:在组织中为空。安特尔。v4。运行时。BailErrorStrategy。graphql上的recoverInline(BailErrorStrategy.java:90)~[antlr4-runtime-4.5.1.jar:4.5.1]。解析器。安特尔。GraphqlParser。名称(GraphqlParser.java:1361)~[graphql-java-3.0.0.jar:na]位于graphql。解析器。安特尔。GraphqlParser。inputValueDefinition(GraphqlParser.java:3099)~[graphql-java-3.0.0.jar:na]位于graphql。解析器。安特尔。GraphqlParser。argumentsDefinition(GraphqlParser.java:3037)~[graphql-java-3.0.0.jar:na]位于graphql。解析器。安特尔。GraphqlParser。fieldDefinition(GraphqlParser.java:2965)~[graphql-java-3.0.0.jar:na]=

怎么了?在你的变体中,你声明了一个字段名createUser,并添加了括号:在GraphQL中,当使用括号时,这意味着你至少有一个输入/参数,输入必须是

拆下支架,它应该可以工作;-)

 类似资料:
  • [错误]生成无法读取1个项目->[帮助1][错误] [错误]项目com.example.angularjs:demo:0.0.1-快照(C:\users\vvk\download\demo\POM.xml)有1个错误[错误] com.example.angularjs:demo:0.0.1-快照:无法解析的父POM:无法传输项目org.springframework.boot:spring-boo

  • Spring Boot是否可以在上下文中正确地加载旧的jar?旧jar中的pom文件是否不会受到影响,因为它引用了一些父级的spring版本以及使用相同版本的jar?或者这些JAR只使用spring boot添加的依赖关系? 有人能建议我哪里做错了吗?

  • 使用maven启动tomcat时,出现以下错误 java.util.concurrent.executionException:org.apache.Catalina.LifecyCleException:在java.util.concurrent.futureTask.report(未知源)在java.util.concurrent.futureTask.get(未知源)启动组件[standar

  • 在 Juno 上成功安装 STS 后,我打开了一个新的 MVC 项目,通过添加所有必需的Spring罐修复了示例 STS 项目中的错误,现在有 2 个问题: > 我找不到选项:“在服务器上运行”(尽管我确实在工作区中设置了tomcat的服务器)。 随着我所做的每一步(清理、删除等),我都会收到以下错误: 生成期间发生错误。在项目“First_STS_Project”上运行生成器“分面项目验证生成器

  • 我试图启动与MIP SDKJava包装器1.8.86在amd64 Windows机器上打包的示例程序。 我已经按照说明将< code>mip_java.dll复制到sdk目录,将< code > file/bins/release/amd64 目录的绝对路径添加到< code>java.library.path系统属性的前面,并将< code>MIP#initialize中的空参数替换为相同的路径

  • 我从Spring Initializr下载了一个spring-boot空项目,编译时它给我以下错误: 我已经尝试了jdk 8和12,看起来它并没有改变什么。 这是我的pom.xml 我已经在这里阅读了所有类似的主题,但我的问题不同。我必须使用Maven,但还没有添加任何插件。