java - 为什么我无法在 Spring-5.0.0.RELEASE 中导入 ApplicationContext

标签 java spring applicationcontext spring-framework-beans

我试图关注 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");

上面的代码行表示无法解析 ApplicationContextClassPathXmlApplicationContext

我试图查明这些类是否已更改为有利于任何其他类,但我在 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/

相关文章:

java - 如何减少 Spring 应用程序上下文中的重复

java - JTextField 在 GridBagLayout 中未对齐

java - 如何在不发送另一个身份验证请求的情况下保持来自跨源(CORS)Spring security的登录 session

java - 与 Maven 依赖项冲突(Spring 和 Hibernate)

spring - Maven 和 Spring Boot - 不可解析的父 pom - repo.spring.io(未知主机)

spring - 运行集成测试时无法加载 ApplicationContext

spring - 如何在 Spring Framework 4 中初始化应用程序上下文

java - 将 Child 转换为 Parent 可以吗?

java - Nack 当前消息之前的所有消息并 Ack 当前消息(rabbitmq,java)

java - 使用 Maven 构建项目时缺少 JUNIT Jar 异常