[Spring] The type org.springframework.core.io.Resource cannot be resolved 에러 해결법

Yunsse·2020년 2월 1일
0

[Spring]

목록 보기
1/2

Spring 실습 도중 에러가 생겼다.

문제 상황

spring 실습을 시작할 때 가장 처음 쓰게되는 구문이다.
여기서 GenericXmlApplicationContext("config/beans.xml");에 에러가 생긴다

public class HelloBeanTest {
	public static void main(String args[]) {
		ApplicationContext context = new GenericXmlApplicationContext("config/beans.xml");  //문제 구문
		hello hello = (Hello)context.getBean("hello");
	}
}

해결 방법

1. import 하여 해결

import org.springframework.context.support.GenericXmlApplicationContext;

2. maven에서 받은 라이브러리를 pom.xml에 추가

The type org.springframework.core.io.Resource cannot be resolved

위 에러 코드를 보면 springframework.core의 라이브러리를 참조하지 못한 것을 확인할 수 있다.
이럴 경우에는 maven 홈페이지에서 spring core을 참조하여 pom.xml에 추가하면 된다
https://mvnrepository.com/artifact/org.springframework/spring-core

위 링크에서 자신에게 맞는 버전을 선택하면 다음과 같은 화면이 나온다.
아래에 떠있는 코드를 복사해서 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>testing</groupId>
  <artifactId>testing</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
  <!---추가한 부분--->
  <dependencies>
	<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.0.0.RELEASE</version>
	</dependency>
  </dependencies>


  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

스프링 너무 짜증난다. 물론 안드로이드보다 낫지만....

profile
yunsse입니다.

0개의 댓글