bean. xml файл не найден, даже если bean. xml файл существует - PullRequest
0 голосов
/ 20 апреля 2020

Я изучаю spring mvc. Я пытался создать файл bean. xml и хочу, чтобы весна прочитала файл, когда программа запустится.

Первый шаг, который я поместил в sr c папка:

У меня есть класс Body как:

package com.ashwin;

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

    public class Body {

        public static void main(String[] args) {
            System.out.println("abc");

            ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
            Human human=context.getBean("heart",Human.class);

            human.startPump();

        }

    }

enter image description here

С тех пор, как я вставил в src /beans.xml Я получил ошибку как:

Apr 20, 2020 9:46:26 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
    at 

Итак, я искал и нашел решение для этого. Итак, я скопировал бобы. xml в папку src/main/resources, но, Я получаю еще одну ошибку:

pr 20, 2020 9:51:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.clearCache()V
    at org.springframework.context.support.AbstractApplicationContext.resetCommonCaches(AbstractApplicationContext.java:924)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:575)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)

Моя зависимость в 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.ashwin</groupId>
  <artifactId>springintro1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>springintro1</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.0.1.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.2.5.RELEASE</version>
</dependency>


  </dependencies>
</project>

Пожалуйста, помогите мне разрешить эту ошибку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...