我试图关注 this PluralSight 上学习 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
并配置了 beans。现在我在导入 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>
最佳答案
请从这里获取所有依赖项: Spring Maven Dependency
看起来您正在使用正确的依赖项:
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
尝试执行mvn clean install
关于java - 为什么我无法在 Spring-5.0.0.RELEASE 中导入 ApplicationContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51019022/