spring boot启动失败

Eric_林 发布于 2017/02/27 15:10
阅读 1K+
收藏 0

按照http://projects.spring.io/spring-boot/#quick-start的步骤启动,但是失败

[WARNING]
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory

        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
        at com.qnvip.demo.App.main(App.java:24)
        ... 6 more
Caused by: java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
        at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:37)
        at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:169)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
        ... 14 more
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 18 more

顾名思义,缺少类org/apache/juli/logging/LogFactory,我电脑上使用是tomat7.0.6,但这是maven构造的项目啊,而且是通过mvn命令启动的,跟我本地tomcat应该没关系的,我很无奈,但没办法,添加了tomcat-juli,但随后提示没有tomcat-catalina,又加了,然后是tomcat-util-scan,全是tomcat的东西,加了tomcat-util-scan之后还是提示找不到这个jar包里面的东西,我只是一个hello world怎么这么命苦,谁有碰到过spring boot的这个问题吗?

 

附上所有代码

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.qnvip</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <tomcat.version>7.0.52</tomcat.version>
  </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!-- 		<dependency> -->
<!-- 		    <groupId>org.apache.tomcat</groupId> -->
<!-- 		    <artifactId>tomcat-juli</artifactId> -->
<!-- 		    <version>9.0.0.M17</version> -->
<!-- 		</dependency> -->
<!-- 		<dependency> -->
<!-- 		    <groupId>org.apache.tomcat</groupId> -->
<!-- 		    <artifactId>tomcat-catalina</artifactId> -->
<!-- 		    <version>9.0.0.M17</version> -->
<!-- 		</dependency> -->
<!-- <dependency> -->
<!--     <groupId>org.apache.tomcat</groupId> -->
<!--     <artifactId>tomcat-util-scan</artifactId> -->
<!--     <version>9.0.0.M17</version> -->
<!-- </dependency> -->
<!-- 	    <dependency> -->
<!-- 		    <groupId>javax.servlet</groupId> -->
<!-- 		    <artifactId>javax.servlet-api</artifactId> -->
<!-- 		</dependency> -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
package com.qnvip.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Hello world!
 *
 */
@RestController
@EnableAutoConfiguration
public class App {
	
	@RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }
	
	public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

mvn spring-boot:run

加载中
0
jayhu
jayhu

先贴出pom.xml的springboot配置看一下

0
snowfog
snowfog

你先看看项目的依赖包里面又没有日志框架,然后在重新build一下项目,然后,你用了RestController,那就不需要@ResponseBody注解

0
y
yamazaki_97

去掉

<tomcat.version>7.0.52</tomcat.version>
返回顶部
顶部