Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用spark缓存数据时SpringBoot Api崩溃_Java_Spring Boot_Apache Spark_Caching - Fatal编程技术网

Java 使用spark缓存数据时SpringBoot Api崩溃

Java 使用spark缓存数据时SpringBoot Api崩溃,java,spring-boot,apache-spark,caching,Java,Spring Boot,Apache Spark,Caching,我正在运行一个springboot应用程序,需要使用spark在内存中缓存一些数据 如果我首先启动API,然后缓存数据,它就可以正常工作 但是如果我首先缓存数据,然后启动API,在这种情况下,应用程序在启动API时崩溃 下面是错误和一小段代码: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/

我正在运行一个springboot应用程序,需要使用spark在内存中缓存一些数据

如果我首先启动API,然后缓存数据,它就可以正常工作

但是如果我首先缓存数据,然后启动API,在这种情况下,应用程序在启动API时崩溃

下面是错误和一小段代码:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.5.RELEASE)

2020-09-08 17:57:51.344  INFO 2866 --- [           main] com.app.api.ApiStart          : Starting ApiStart v1.0-SNAPSHOT on my-vm1 with PID 2866 (/home/app/AscBasicInfoDev-1.0-SNAPSHOT.jar started by app in /home/app/)
2020-09-08 17:57:51.345  INFO 2866 --- [           main] com.app.api.ApiStart          : No active profile set, falling back to default profiles: default
2020-09-08 17:57:51.851  INFO 2866 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@372f7bc: startup date [Tue Sep 08 17:57:51 UTC 2020]; root of context hierarchy
2020-09-08 17:57:53.182  INFO 2866 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2020-09-08 17:57:53.937  INFO 2866 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-09-08 17:57:53.989  INFO 2866 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-09-08 17:57:53.989  INFO 2866 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.34
2020-09-08 17:57:54.010  INFO 2866 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2020-09-08 17:57:54.053 ERROR 2866 --- [cat-startStop-1] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_261]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_261]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:942) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1420) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1410) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_261]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_261]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_261]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_261]
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@138f2be]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4907) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5042) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 6 common frames omitted
Caused by: java.lang.Error: factory already defined
    at java.net.URL.setURLStreamHandlerFactory(URL.java:1134) ~[na:1.8.0_261]
    at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.<init>(TomcatURLStreamHandlerFactory.java:130) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.getInstanceInternal(TomcatURLStreamHandlerFactory.java:53) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.register(TomcatURLStreamHandlerFactory.java:77) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.webresources.StandardRoot.registerURLStreamHandlerFactory(StandardRoot.java:699) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.webresources.StandardRoot.initInternal(StandardRoot.java:682) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107) [tomcat-embed-core-8.5.34.jar!/:8.5.34]
    ... 10 common frames omitted
        
        // This will create a sparksession
        SparkConnect sparkConnect = new SparkConnect();
        sparkConnect.createSparkSession();
        

        // This will run spark.sql() and cache some data and fetch the count
        // If this is called after SpringApplication.run, then also it works fine
        sparkConnect.cacheDataset();


        // This will start the springboot api
        // This is where application crashes
        SpringApplication.run(ApiStart.class, args);