【发布时间】:2018-06-25 08:20:15
【问题描述】:
我试图按照 PluralSight 上的 this 教程学习 Spring。本教程基于 spring 4.3.2,而我想在 5.0.0 上学习它。我使用 mvn 导入了 spring 依赖项:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
</dependencies>
所有依赖项都已正常导入。我创建了我的 applicationContext.xml 并配置了 bean。现在我在导入 ApplicationContext 时遇到问题。
ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
上面这行代码说无法解析ApplicationContext和ClassPathXmlApplicationContext。
我试图找出这些类是否已更改为支持任何其他类,但我在 Spring 网站上没有找到任何此类信息。
5.0.0 之后我是否遗漏了什么或者使用 Spring 的方式有什么变化
我的 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>
<groupId>com.saurabh</groupId>
<artifactId>spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring</name>
<description>My first attempt at learning spring from Pluralsight</description>
<!-- the stuff above this was generated automatically while I wrote all that is below -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
编译时是否检查了依赖项是否已下载
-
org.springframework.context.support.ClassPathXmlApplicationContext 在 spring-context-X.X.X.RELEASE.jar 中。你在 CLASSPATH 上有那个 jar 吗?
-
是的。我可以在构建路径中看到所有的 spring jar。
-
因为它是一个 maven 项目,你能发布你的完整
pom.xml吗?此外,您是否尝试过mvn clean compile? -
清理本地存储库 (
mvn dependency:purge-local-repository) 并重新下载依赖项 (mvn package)。
标签: java spring applicationcontext spring-framework-beans