无法启动Spring-Boot示例

java spring maven spring-boot

9974 观看

3回复

927 作者的声誉

我正在尝试弹簧靴样品。这是我一直试图运行的示例spring-boot-sample-tomcat

按照指示,我已经运行mvn package并且成功了。但是当运行jar时java -jar target/spring-boot-sample-tomcat-0.5.0.BUILD-SNAPSHOT.jar,我得到以下异常。

请确认是否有任何需要放入类路径的罐子。或者如何让它运行。

链接到正在使用的pom.xml

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
        at java.lang.Class.getDeclaredMethod(Class.java:1935)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at org.springframework.boot.loader.LaunchedURLClassLoader.findClass(LaunchedURLClassLoader.java:110)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:93)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:65)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 5 more
作者: Kunal Jha 的来源 发布者: 2013 年 9 月 20 日

回应 (3)


1

2023 作者的声誉

我刚刚执行了:

$ git fetch upstream
$ git merge upstream/master
Already up-to-date.
$ cd spring-boot-samples/spring-boot-sample-tomcat/
$ mvn clean package && java -jar target/spring-boot-sample-tomcat-0.5.0.BUILD-SNAPSHOT.jar
...
Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
...
2013-09-23 08:52:33.713  INFO 698 --- [           main] o.s.b.s.tomcat.SampleTomcatApplication   : Starting SampleTomcatApplication on retina with PID 698 (/Users/gturnquist/src/spring-boot/spring-boot-samples/spring-boot-sample-tomcat/target/spring-boot-sample-tomcat-0.5.0.BUILD-SNAPSHOT.jar started by gturnquist)
2013-09-23 08:52:33.753  INFO 698 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@21301fa: startup date [Mon Sep 23 08:52:33 CDT 2013]; root of context hierarchy
2013-09-23 08:52:34.673  INFO 698 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2013-09-23 08:52:34.674  INFO 698 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.42
2013-09-23 08:52:34.753  INFO 698 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2013-09-23 08:52:34.754  INFO 698 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1004 ms
2013-09-23 08:52:34.902  INFO 698 --- [ost-startStop-1] o.s.b.s.tomcat.SampleTomcatApplication   : ServletContext initialized
2013-09-23 08:52:34.918  INFO 698 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2013-09-23 08:52:34.919  INFO 698 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2013-09-23 08:52:34.991  INFO 698 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2013-09-23 08:52:35.127  INFO 698 --- [ost-startStop-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.boot.sample.tomcat.web.SampleController.helloWorld()
2013-09-23 08:52:35.169  INFO 698 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2013-09-23 08:52:35.169  INFO 698 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2013-09-23 08:52:35.377  INFO 698 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 458 ms
2013-09-23 08:52:37.548  INFO 698 --- [           main] o.s.b.s.tomcat.SampleTomcatApplication   : Started SampleTomcatApplication in 4.299 seconds

也许您需要更新克隆并重建?

作者: gregturn 发布者: 23.09.2013 01:54

4

663 作者的声誉

决定

您可以尝试将此细分添加到您的pom:

<properties>
  <start-class>org.springframework.boot.sample.tomcat.SampleTomcatApplication</start-class>
</properties>

这定义了显式使用的“main”。Spring boot应该自动获取main,但显式是一个很好的方法。这是我能够使用“java -jar”调用工作来获得另一个项目的唯一方法。

作者: sanimalp 发布者: 18.10.2013 04:43

0

1 作者的声誉

我有同样的问题,我的问题是我在属性的start-class上配置了错误的类,一旦我删除它,一切都很好:

<properties>
  <start-class>wrong class here</start-class>  <-- REMOVE THIS LINE
</properties>
作者: user3584001 发布者: 30.04.2019 07:53
32x32