The type org.springframework.context.ConfigurableApplicationContext cannot be resolved The type org.springframework.context.ConfigurableApplicationContext cannot be resolved

The type org.springframework.context.ConfigurableApplicationContext cannot be resolved

当我在start.spring.io 上创建freemarker Test程序时,发生了以下错误。

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  4.     <modelVersion>4.0.0</modelVersion>  
  5.   
  6.     <groupId>com.jun</groupId>  
  7.     <artifactId>springInitializr</artifactId>  
  8.     <version>0.0.1-SNAPSHOT</version>  
  9.     <packaging>jar</packaging>  
  10.   
  11.     <name>springInitializr</name>  
  12.     <description>Demo project for Spring Boot</description>  
  13.   
  14.     <parent>  
  15.         <groupId>org.springframework.boot</groupId>  
  16.         <artifactId>spring-boot-starter-parent</artifactId>  
  17.         <version>1.5.3.RELEASE</version>  
  18.         <relativePath/> <!-- lookup parent from repository -->  
  19.     </parent>  
  20.   
  21.     <properties>  
  22.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  23.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
  24.         <java.version>1.8</java.version>  
  25.     </properties>  
  26.   
  27.     <dependencies>  
  28.         <dependency>  
  29.             <groupId>org.springframework.boot</groupId>  
  30.             <artifactId>spring-boot-starter-freemarker</artifactId>  
  31.         </dependency>  
  32.         <dependency>  
  33.             <groupId>org.springframework.boot</groupId>  
  34.             <artifactId>spring-boot-starter-web</artifactId>  
  35.         </dependency>  
  36.   
  37.         <dependency>  
  38.             <groupId>org.springframework.boot</groupId>  
  39.             <artifactId>spring-boot-devtools</artifactId>  
  40.             <scope>runtime</scope>  
  41.         </dependency>  
  42.         <dependency>  
  43.             <groupId>org.springframework.boot</groupId>  
  44.             <artifactId>spring-boot-starter-test</artifactId>  
  45.             <scope>test</scope>  
  46.         </dependency>  
  47.     </dependencies>  
  48.   
  49.     <build>  
  50.         <plugins>  
  51.             <plugin>  
  52.                 <groupId>org.springframework.boot</groupId>  
  53.                 <artifactId>spring-boot-maven-plugin</artifactId>  
  54.             </plugin>  
  55.         </plugins>  
  56.     </build>  
  57. </project>  
[html]  view plain  copy
  1. import org.springframework.boot.SpringApplication;  
  2. import org.springframework.boot.autoconfigure.SpringBootApplication;  
  3.   
  4.   
  5. @SpringBootApplication  
  6. public class SpringInitializrApplication {  
  7.   
  8.   
  9. <span style="white-space:pre;"> </span>public static void main(String[] args) {  
  10. <span style="white-space:pre;">     </span>SpringApplication.run(SpringInitializrApplication.class, args);  
  11. <span style="white-space:pre;"> </span>}  
  12. }  
在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
它现在可以正常工作

[java]  view plain  copy
  1.   
[html]  view plain  copy
  1.   
[java]  view plain  copy
  1.   
[html]  view plain  copy
  1.   
[java]  view plain  copy
  1.   
[html]  view plain  copy
  1.   

猜你喜欢

转载自blog.csdn.net/svneclipse/article/details/80711900
今日推荐