[Spring] getBean(String) is undefined for the type ApplicationContext 에러 해결 방법

Yunsse·2020년 2월 1일
0

[Spring]

목록 보기
2/2

문제 상황


이렇게 getBean 메소드마다 오류 메세지가 뜬다.
빨간 줄에 커서를 가져다 대 봐도 context에 cast를 추가하라는 개소리 뿐...

import도

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

다 했는데 계속 에러가 떴다.
구글에 검색해봐도 가지각색 java 메소드들의 undefined 문제만 나온다!

해결 방법

사실 엄청나게 간단했다.
ApplicationContext를 import 해줬지만.
좌측 eclipse repository를 보면
Referenced Libraries > spring-context-n.n.n.RELEASED.jar 에
context.support는 있지만
context.ApplicationContext는 없었다...

다시 또 maven을 활용.
https://mvnrepository.com/artifact/org.springframework/spring-context
에서 최신 버전을 복사하여 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>5.2.3.RELEASE</version>
	</dependency>
	
	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-context</artifactId>
	    <version>5.2.3.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개의 댓글