簡體   English   中英

Spring Boot-無法在WebLogic 12c中初始化ServletRegistrationBean

[英]Spring Boot - Failed to initialize ServletRegistrationBean in WebLogic 12c

我們正在WebLogic 12c中運行GraphQL示例Java應用程序,但是在啟動過程中servlet遇到了一些錯誤。

如下所示,已配置servlet並使用ServletRegistrationBean注冊我們的servlet:

@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass(DispatcherServlet.class)
@ConditionalOnBean({GraphQLSchema.class, GraphQLSchemaProvider.class})
@ConditionalOnProperty(value = "graphql.servlet.enabled", havingValue = "true", matchIfMissing = true)
@AutoConfigureAfter({GraphQLJavaToolsAutoConfiguration.class, SpringGraphQLCommonAutoConfiguration.class})
@EnableConfigurationProperties(GraphQLServletProperties.class)

public class GraphQLWebAutoConfiguration {
    ...
    @Bean
    @ConditionalOnMissingBean
    public GraphQLServlet graphQLServlet(GraphQLSchemaProvider schemaProvider, ExecutionStrategyProvider executionStrategyProvider) {
        return new SimpleGraphQLServlet(schemaProvider, executionStrategyProvider, listeners, instrumentation, errorHandler, contextBuilder);
    }

    @Bean
    ServletRegistrationBean graphQLServletRegistrationBean(GraphQLServlet servlet) {
        ServletRegistrationBean bean = new ServletRegistrationBean(servlet, graphQLServletProperties.getServletMapping());
        bean.setLoadOnStartup(1);
        return bean;
    }
}

在weblogic服務器日志中,它輸出錯誤:

<Oct 2, 2017 1:51:28 PM SGT> <Error> <HTTP> <BEA-101125> <[ServletContext@933807824[app:CPRES module:CPRES path:null spec-version:3.1]] Error occurred while instantiating servlet: "simpleGraphQLServlet".
java.lang.InstantiationException: graphql.servlet.SimpleGraphQLServlet
        at java.lang.Class.newInstance(Class.java:427)
        at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:252)
        at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:245)
        at weblogic.servlet.internal.WebComponentContributor.createServletInstance(WebComponentContributor.java:274)
        at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.newServletInstanceIfNecessary(StubSecurityHelper.java:365)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodException: graphql.servlet.SimpleGraphQLServlet.<init>()
        at java.lang.Class.getConstructor0(Class.java:3082)
        at java.lang.Class.newInstance(Class.java:412)
        at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:252)
        at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:245)
        at weblogic.servlet.internal.WebComponentContributor.createServletInstance(WebComponentContributor.java:274)
        Truncated. see log file for complete stacktrace
>
<Oct 2, 2017 1:51:28 PM SGT> <Error> <HTTP> <BEA-101216> <Servlet: "simpleGraphQLServlet" failed to preload on startup in Web application: "CPRES".
javax.servlet.ServletException: Servlet class: 'graphql.servlet.SimpleGraphQLServlet' couldn't be instantiated
        at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:326)
        at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:294)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
        at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:196)
        at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
        Truncated. see log file for complete stacktrace
>
<Oct 2, 2017 1:51:29 PM SGT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "19094957742917053" for task "130" on [partition-name: DOMAIN]. Error is: "weblogic.application.ModuleException: javax.servlet.ServletException: Servlet class: 'graphql.servlet.SimpleGraphQLServlet' couldn't be instantiated"
weblogic.application.ModuleException: javax.servlet.ServletException: Servlet class: 'graphql.servlet.SimpleGraphQLServlet' couldn't be instantiated

看起來weblogic正在嘗試創建一個新的servlet實例,而不是由Spring上下文創建和管理的ServletBean SimpleGraphQLServlet。

有進步嗎? 謝謝。

解決方法是編寫一個Servlet包裝器類,如下所示:

public class DelegateGraphQLServlet extends HttpServlet {
    protected GraphQLServlet graphQLServlet;

    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);

        ApplicationContext ac = (ApplicationContext) servletConfig.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        this.graphQLServlet = (GraphQLServlet)ac.getBean("graphQLServlet");
    }

     public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
         graphQLServlet.service(req, res);
     }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM