按照视频学习使用idea和maven创建spring项目,创建ApplicationContext对象时系统报红,怀疑是maven未成功导入spring依赖但不确定
开发环境:idea
import com.kuang.pojo.Hello;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("services.xml", "daos.xml");
Hello hello=(Hello) context.getBean("Hello");
}
}
不能识别ApplicationContext
检查pom中引入的依赖,如下,个人感觉是没问题的但不确定
<?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>org.example</groupId>
<artifactId>MySpringA</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>spring-01-ioc1</module>
<module>spring-02-hellospring</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.9.RELEASE</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
我希望下面这行可以正常使用不爆红
ApplicationContext context = new ClassPathXmlApplicationContext("services.xml", "daos.xml");
换一个高点的版本。