ресурс пути к классу [pointsconfig.properties] не может быть открыт, потому что он не существует

Г-н Аскер

Я пытаюсь изучить основы работы с Spring. Я использую org.springframework.beans.factory.config.PropertyPlaceholderConfigurerфайл sping.xml для печати свойств PointA, но получаю сообщение об ошибке ниже.

Класс Triagle

package org.stack;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Triangle  {
    private Point PointA;
    private Point PointB;
    private Point PointC;
    private ApplicationContext context = null;

    public Point getPointA() {
        return PointA;
    }

    public void setPointA(Point pointA) {
        PointA = pointA;
    }

    public Point getPointB() {
        return PointB;
    }

    public void setPointB(Point pointB) {
        PointB = pointB;
    }

    public Point getPointC() {
        return PointC;
    }

    public void setPointC(Point pointC) {
        PointC = pointC;
    }

    public void draw() {

        System.out.println("Point A = (" + getPointA().getX() + ", "
                + getPointA().getY() + ")");
        System.out.println("Point B = (" + getPointB().getX() + ", "
                + getPointB().getY() + ")");
        System.out.println("Point C = (" + getPointC().getX() + ", "
                + getPointC().getY() + ")");

    }

}

DrawingApp

package org.stack;


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


public class DrawingApp {

    public static void main(String[] args) {


        AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        context.registerShutdownHook();
        Triangle triangle =  (Triangle) context.getBean("triangle");
        triangle.draw();

    }
}

spring.xml

</bean>

<!-- We intialize here 3 Points objects -->
<bean id="pointA" class="org.stack.Point">
    <property name="x" value="${PointA.pointY}" />
    <property name="y" value="${PointA.pointY}" />
</bean>



<bean id="pointB" class="org.stack.Point">
    <property name="x" value="-20" />
    <property name="y" value="0" />
</bean>

<bean id="pointC" class="org.stack.Point">
    <property name="x" value="20" />
    <property name="y" value="0" />
</bean>


<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations" value="pointsconfig.properties"></property>
</bean>

файл pointsconfig.properties

PointA.pointX=0
PointA.pointY=0

введите описание изображения здесь

ошибка

Mai 31, 2016 1:25:24 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFORMATION: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@619a5dff: startup date [Tue May 31 13:25:24 CEST 2016]; root of context hierarchy
Mai 31, 2016 1:25:24 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFORMATION: Loading XML bean definitions from class path resource [spring.xml]
Mai 31, 2016 1:25:25 PM org.springframework.beans.factory.config.PropertyPlaceholderConfigurer loadProperties
INFORMATION: Loading properties file from class path resource [pointsconfig.properties]
Mai 31, 2016 1:25:25 PM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNUNG: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [pointsconfig.properties] cannot be opened because it does not exist
Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [pointsconfig.properties] cannot be opened because it does not exist
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:89)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at org.stack.DrawingApp.main(DrawingApp.java:14)
Caused by: java.io.FileNotFoundException: class path resource [pointsconfig.properties] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:153)
    at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
    at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:80)
    ... 7 more
Книга

Переместите pointsconfig.propertiesфайл в каталог ресурсов.

Эта статья взята из Интернета, укажите источник при перепечатке.

Если есть какие-либо нарушения, пожалуйста, свяжитесь с[email protected] Удалить.

Отредактировано в
0

я говорю два предложения

0обзор
Войти в системуУчаствуйте в комментариях

Статьи по теме

TOP список

  1. 1

    Распределение Рэлея Curve_fit на Python

  2. 2

    Merging legends in plotly subplot

  3. 3

    Как я могу нарисовать заполненный прямоугольник в JFreeChart?

  4. 4

    Проблема с window.print в Safari

  5. 5

    Перебирайте несколько столбцов в фрейме данных Panda и находите уникальные значения подсчета

  6. 6

    JetBrains Rider enable-migrations для ASP.NET MVC на Mac

  7. 7

    migrate MongoDB container service - mongodump command not found

  8. 8

    Как создать переменную с использованием класса Color, который включает только выбранные цвета?

  9. 9

    Ошибка XDG0062: не удалось установить «Контент». в режиме навигации MUXC

  10. 10

    Как загрузить ZIP-файл в Nexus с помощью Maven и избежать создания артефакта pom в Nexus?

  11. 11

    QString удалить последние символы

  12. 12

    Symfony 4, Postgres - `Неверное значение параметра client_encoding:« utf8mb4 »` при выполнении команды doctrine

  13. 13

    HTML Body говорит cz-shortcut-listen = "true" с инструментами разработчика Chrome?

  14. 14

    В типе Observable <unknown> отсутствуют следующие свойства из типа Promise <any>.

  15. 15

    Как создать простую анимацию в Xamarin с помощью SkiaSharp

  16. 16

    Установка pip с использованием Python 2.7, установленного в ArcGIS

  17. 17

    Qt - не растягивать виджеты в QVBoxLayout

  18. 18

    How to convert C++/CLI string to const char*

  19. 19

    sbt: Как разрешить зависимости Maven, использующие свойства Maven

  20. 20

    Flutter: Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: '' (OS Error: Read-only file system, errno = 30)

  21. 21

    Как добавить Swagger в веб-API с поддержкой OData, работающий на ASP.NET Core 3.1

популярныйтег

файл