开发环境:
1.jdk1.8
2.maven3.5
3.eclipse
pom.xml配置如下
<?xml version="1.0" encoding="UTF-8"?>
<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>springboot.demo</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-demo1</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
然后启动时找不到包。我首先想到的是1.8的坑,因为在几年前我第一次使用1.8时遇到很多坑,但是又突然想到现在1.8的jdk已经很稳定了。所有想到可能是spring版本的一些冲突。
报错信息:
根据上述pom.xml的配置得到的Spring版本是4.3,Springboot是1.5.6,然后将Springboot的版本换为1.5.9成功运行。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/>
</parent>
问题解决。
报错原因:
1.根据上面的描述可以知道这是版本冲突问题
2.后来又遇到过一个类似错误,报的也是找不到包,但是没有直接依赖,提示是不能读取maven里面的某个包,后来把maven本地库删除后重新构建解决。
3.同事遇到一个类似的找不到类,是一个servlet相关包,最后是把Eclipse换了就解决了...
4.也有可能是模板文件没有找到,这种情况建议看下浏览器开发者工具下network(谷歌),是否已经访问了控制器,或者在控制器打印或断点都能检查这一项
建议:如果1个小时解决不了,就果断放弃,并重新创建一个项目。
神奇的Springboot...