SpringBoot配置官网quikstart报错,菜鸟求大神

x西门m 发布于 2017/09/18 21:08
阅读 972
收藏 0

报错信息

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/util/ClassUtils
    at org.springframework.boot.SpringApplication.deduceWebEnvironment(SpringApplication.java:257)
    at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:248)
    at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:225)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.ximen.SpringBootTest.FirstSpringBoot.main(FirstSpringBoot.java:19)
Caused by: java.lang.ClassNotFoundException: org.springframework.util.ClassUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more



求大神解答

pom.xml配置

<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>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
  </parent>
  <groupId>com.ximen</groupId>
  <artifactId>SpringBootTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

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

  <properties>
  	<jdk.version>1.8</jdk.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
<build>  
	<finalName>bootfirst</finalName>
    <plugins>  
        <plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-compiler-plugin</artifactId>  
            <version>${maven-compiler-plugin.version}</version>  
            <configuration>  
                <source>${jdk.version}</source>  
                <target>${jdk.version}</target>
                <encode>${project.build.sourceEncoding}</encode> 
            </configuration>  
        </plugin>  
    </plugins>  
</build>  
</project>

java测试类

package com.ximen.SpringBootTest;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class FirstSpringBoot {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(FirstSpringBoot.class, args);
    }
}

 

加载中
0
miss_all
miss_all

http://start.spring.io/   用这里构建

0
哎码
哎码

找不到类,缺包或者是包冲突吧

java.lang.ClassNotFoundException: org.springframework.util.ClassUtils

另外用@springbootapplication,里面包含了

ComponentScan
EnableAutoConfiguration
SpringBootConfiguration

这几个注解,所以除非需要自定义扫描包,否则尽量直接用

SpringBootApplication
0
x西门m
x西门m

今天灵机一动,找到了问题所在,正如报错,缺少包

因为用的maven,当初在下载springframework中的包的时候可能没下完就给关了

解决方法:
到本地maven库(我的是C:\Users\ximen\.m2\repository),删除springframework,然后到eclipse中右键项目,maven-》update  project,会重新下载相关包,然后运行,成功

任重道元
任重道元
你也是个人才啊
阿信sxq
阿信sxq
你这也是奇葩行为
返回顶部
顶部