当我在start.spring.io 上创建freemarker Test程序时,发生了以下错误。
<?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>com.jun</groupId>
<artifactId>springInitializr</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springInitializr</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</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>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringInitializrApplication {
public static void main(String[] args) {
SpringApplication.run(SpringInitializrApplication.class, args);
}
}
在main中的run方法报出异常,“The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.context.ConfigurableApplicationContext. Fix the build path then try building this project ” project前有小红叹号,但是在 java Build Path中并没有出现任何异常。
在markers view 中提示:“The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files”
经查询发现 在 这里 发生了和我类似的问题, 原来问题是出现在maven中缓存上,maven的缓存已损坏
按照以下步骤解决:
在命令行中转到项目目录。
确保您的POM.xml与您的命令行在同一个目录中
运行命令 mvn dependency:purge-local-repository
如果您收到构建成功的消息,表示错误已解决。
如果仍然存在错误,请删除(〜/ .m2 / repository / org / springframework)文件夹并运行 mvn package
它现在可以正常工作