0

当我从 Idea 运行它时,效果很好。我使用gradle bootJar. 当我运行它时,我得到:

java -jar server-0.0.1-SNAPSHOT.jar                                     

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

2020-02-05 12:22:22.183  INFO 22473 --- [           main] pl.daniel.demo.DemoApplication     : Starting DemoApplication on daniel-core with PID 22473 (/home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar started by daniel in /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs)
2020-02-05 12:22:22.186  INFO 22473 --- [           main] pl.daniel.demo.DemoApplication     : No active profile set, falling back to default profiles: default
2020-02-05 12:22:23.242  INFO 22473 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-02-05 12:22:23.265  INFO 22473 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15ms. Found 0 repository interfaces.
2020-02-05 12:22:23.679  INFO 22473 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$2ff842b0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-02-05 12:22:24.027  INFO 22473 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9001 (http)
2020-02-05 12:22:24.070  INFO 22473 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-02-05 12:22:24.071  INFO 22473 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.26]
2020-02-05 12:22:24.184  INFO 22473 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-02-05 12:22:24.184  INFO 22473 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1946 ms
2020-02-05 12:22:24.219 ERROR 22473 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jerseyConfig' defined in URL [jar:file:/home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/pl/daniel/demo/JerseyConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [pl.daniel.demo.JerseyConfig]: Constructor threw exception; nested exception is org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
2020-02-05 12:22:24.256  INFO 22473 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-02-05 12:22:24.265  WARN 22473 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2020-02-05 12:22:24.277  INFO 22473 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-02-05 12:22:24.283 ERROR 22473 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at pl.daniel.demo.DemoApplication.main(DemoApplication.java:17) ~[classes!/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[server-0.0.1-SNAPSHOT.jar:na]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[server-0.0.1-SNAPSHOT.jar:na]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) ~[server-0.0.1-SNAPSHOT.jar:na]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) ~[server-0.0.1-SNAPSHOT.jar:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:124) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:416) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:180) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        ... 14 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jerseyConfig' defined in URL [jar:file:/home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/pl/daniel/demo/JerseyConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [pl.daniel.demo.JerseyConfig]: Constructor threw exception; nested exception is org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:392) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:211) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:202) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:96) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:85) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:253) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:227) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:459) ~[tomcat-embed-core-9.0.26.jar!/:9.0.26]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:105) ~[spring-boot-2.1.9.RELEASE.jar!/:2.1.9.RELEASE]
        ... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jerseyConfig' defined in URL [jar:file:/home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/pl/daniel/demo/JerseyConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [pl.daniel.demo.JerseyConfig]: Constructor threw exception; nested exception is org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1303) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1255) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1175) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        ... 68 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [pl.daniel.demo.JerseyConfig]: Constructor threw exception; nested exception is org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        ... 80 common frames omitted
Caused by: org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
        at org.glassfish.jersey.server.internal.scanning.JarZipSchemeResourceFinderFactory.create(JarZipSchemeResourceFinderFactory.java:90) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.internal.scanning.JarZipSchemeResourceFinderFactory.create(JarZipSchemeResourceFinderFactory.java:66) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.addResourceFinder(PackageNamesScanner.java:283) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.init(PackageNamesScanner.java:199) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.<init>(PackageNamesScanner.java:155) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.internal.scanning.PackageNamesScanner.<init>(PackageNamesScanner.java:111) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.ResourceConfig.packages(ResourceConfig.java:677) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.ResourceConfig.packages(ResourceConfig.java:657) ~[jersey-server-2.27.jar!/:na]
        at pl.daniel.demo.JerseyConfig.registerEndpoints(JerseyConfig.java:52) ~[classes!/:na]
        at pl.daniel.demo.JerseyConfig.<init>(JerseyConfig.java:29) ~[classes!/:na]
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[spring-beans-5.1.10.RELEASE.jar!/:5.1.10.RELEASE]
        ... 82 common frames omitted
Caused by: java.io.FileNotFoundException: /home/daniel/tutorials/clean_architecture_tutorial/server/build/libs/server-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes (No such file or directory)
        at java.base/java.io.FileInputStream.open0(Native Method) ~[na:na]
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219) ~[na:na]
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157) ~[na:na]
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112) ~[na:na]
        at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86) ~[na:na]
        at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:184) ~[na:na]
        at java.base/java.net.URL.openStream(URL.java:1140) ~[na:na]
        at org.glassfish.jersey.server.internal.scanning.JarZipSchemeResourceFinderFactory.getInputStream(JarZipSchemeResourceFinderFactory.java:178) ~[jersey-server-2.27.jar!/:na]
        at org.glassfish.jersey.server.internal.scanning.JarZipSchemeResourceFinderFactory.create(JarZipSchemeResourceFinderFactory.java:88) ~[jersey-server-2.27.jar!/:na]
        ... 96 common frames omitted

我知道这是一个与扫描罐子内的球衣问题有关的问题,我已经在网上尝试了所有可能的解决方案,我可以找到 fe:

无法从 spring-boot jersey 运行生成的 jar

https://www.ivankrizsan.se/2016/12/06/jersey-and-spring-boot-standalone-jar-files/

https://github.com/spring-projects/spring-boot/issues/7496

https://github.com/spring-projects/spring-boot/issues/3260

Spring Boot 和 Jersey 产生 ClassNotFound

https://github.com/jersey/jersey/pull/196

https://github.com/spring-projects/spring-boot/issues/1345

尝试从 jar 文件运行时,Spring Boot 应用程序不会运行

我什至添加了: https://docs.spring.io/spring-boot/docs/1.5.x/reference/htmlsingle/#howto-extract-specific-libraries-when-an-executable-jar-runs来构建文件。

bootJar {
    requiresUnpack '**/api-0.0.1-SNAPSHOT.jar'
}

我的项目是多模块的。它由

  - root
  ---- api
  ---- server

Api 仅与 jaxrs 接口有关,服务器是带有球衣的 spring boot。这里有详细的文件列表:

.
├── api
│   ├── build.gradle
│   └── src
│       └── main
│           └── java
│               └── pl
│                   └── daniel
│                       └── demo
│                           ├── model
│                           │   ├── ApiErrorMessage.java
│                           │   └── UserDto.java
│                           └── resources
│                               ├── ApiResource.java
│                               ├── UserRolesResource.java
│                               └── UsersResource.java
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── README.md
├── server
│   ├── build.gradle
│   └── src
│       ├── integration
│       │   └── java
│       │       └── pl
│       │           └── daniel
│       │               └── demo
│       │                   ├── BaseIT.java
│       │                   ├── DatabaseContainerTest.java
│       │                   └── resources
│       │                       ├── ApiResourceTest.java
│       │                       └── ResourceIT.java
│       ├── main
│       │   ├── java
│       │   │   └── pl
│       │   │       └── daniel
│       │   │           └── demo
│       │   │               ├── BasicAuthenticationRestSecurityFilter.java
│       │   │               ├── CombinedSwaggerResourcesProvider.java
│       │   │               ├── DemoApplication.java
│       │   │               ├── GenericExceptionMapper.java
│       │   │               ├── JerseyConfig.java
│       │   │               └── resources
│       │   │                   ├── ApiController.java
│       │   │                   ├── UserRolesController.java
│       │   │                   ├── UsersController.java
│       │   └── resources
│       │       ├── application.yaml
│       │       └── static
│       │           ├── index.html
│       │           └── ui
│       └── test
│           └── java
│               └── pl
│                   └── daniel
│                       └── demo
│                           └── resources
│                               ├── ApiResourceTest.java
│                               ├── UserRolesResourceTest.java
│                               └── UsersResourceTest.java
├── settings.gradle

我还删除了 api 项目,并将其所有类移至服务器项目,但错误仍然存​​在。

这是我的球衣 conf 课:

@Component
@ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {

    private static final String RESOURCE_PACKAGE_NAME = JerseyConfig.class.getPackage().getName();

    public JerseyConfig() {
        this.registerEndpoints();
        this.configureSwagger2();
        property(ServletProperties.FILTER_FORWARD_ON_404, true);
    }

    public void configureSwagger2() {
        BeanConfig swaggerConfig = new BeanConfig();
        swaggerConfig.setBasePath("/api");
        SwaggerConfigLocator.getInstance().putConfig(SwaggerContextService.CONFIG_ID_DEFAULT, swaggerConfig);

        packages(getClass().getPackage().getName(),
                ApiListingResource.class.getPackage().getName());
    }


    private void registerEndpoints() {
        //packages(RESOURCE_PACKAGE_NAME);
        register(ApiResource.class);
        register(UserRolesResource.class);
        register(UsersResource.class);
    }
}

我的选择已经不多了。请帮助我。

4

2 回答 2

0

这是基于名称的动态扫描类的工作版本(在我的情况下为 *Controller)

    package pl.daniel.demo;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.stereotype.Component;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.ext.Provider;
import java.util.regex.Pattern;

@Component
@ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {
    private Logger LOGGER = LoggerFactory.getLogger(JerseyConfig.class);
    private static final String RESOURCE_PACKAGE_NAME = JerseyConfig.class.getPackage().getName();

    public JerseyConfig() {
        this.registerEndpoints();
        property(ServletProperties.FILTER_FORWARD_ON_404, true);
    }

    private void registerEndpoints() {
        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
        provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(".*Controller")));
        provider.findCandidateComponents(RESOURCE_PACKAGE_NAME).forEach(beanDefinition -> {
            try {
                LOGGER.info("-----> Registering {} to jersey config", beanDefinition.getBeanClassName());
                register(Class.forName(beanDefinition.getBeanClassName()));
            } catch (ClassNotFoundException e) {
                LOGGER.warn("Failed to register: {}", beanDefinition.getBeanClassName());
            }
        });
    }
}

感谢:https ://stackoverflow.com/a/42222252/2794446

于 2020-02-06T10:01:34.993 回答
0

好的,我找到了它现在起作用的原因。在我的情况下,这段代码使它失败(swagger configuration):

    public void configureSwagger2() {
        BeanConfig swaggerConfig = new BeanConfig();
        swaggerConfig.setBasePath("/api");
        SwaggerConfigLocator.getInstance().putConfig(SwaggerContextService.CONFIG_ID_DEFAULT, swaggerConfig);

        packages(getClass().getPackage().getName(),
                ApiListingResource.class.getPackage().getName());
    }

当然,我必须将资源注册更改为:

private void registerEndpoints() {
    //packages(RESOURCE_PACKAGE_NAME);
    register(ApiResource.class);
    register(UserRolesResource.class);
    register(UsersResource.class);
}
于 2020-02-05T17:36:50.457 回答