无法打开类路径资源[pointsconfig.properties],因为它不存在

阿斯克先生

我正在尝试学习Spring框架的基础。org.springframework.beans.factory.config.PropertyPlaceholderConfigurer在sping.xml中使用来打印PointA的属性,但出现以下错误。

三角类

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 条评论
登录 后参与评论

相关文章

无法打开类路径资源[application.properties],因为它不存在

无法打开Spring类路径资源[applicationContext.xml],因为它不存在

类路径资源 [de/ifd/remote/DatabaseService.class] 无法打开,因为它不存在

为什么我得到的类路径资源[src / main / resources / databaseconfig.properties]无法打开,因为它不存在错误?

java.io.FileNotFoundException:类路径资源[WEB-INF / classes / library.properties]无法打开,因为它不存在

java.io.FileNotFoundException:类路径的资源不能打开,因为它不存在

类路径资源[org / springframework / boot / autoconfigure / web / ServerPropertiesAutoConfiguration.class]无法打开,因为它不存在

无法打开类路径资源[org / quartz / impl / jdbcjobstore / tables_h2.sql],因为它不存在

类路径资源[org / apache / ibatis / plugin / Interceptor.class]无法打开,因为它不存在

Spring Boot 1.4:类路径资源[]无法解析为URL,因为它不存在

Spring Data JPA:类路径资源[]无法解析为URL,因为它不存在

@PropertySource无法打开,因为它不存在

Spring @PropertySource无法打开,因为它不存在

WebSecurityConfigurerAdapter.class]无法打开,因为它不存在

找不到路径“ SharePath”,因为它不存在

找不到路径_,因为它不存在

找不到路径,因为它不存在

找不到路径,因为它不存在

Pip 无法安装 tensorflow 因为它不存在

找不到Spring类路径资源,因为它不存在

添加了新的bean.xml并获取具有根本原因的类路径资源[Spring-Mail.xml]无法打开,因为它不存在]

无法打开类路径资源[applicationContext.xml],因为使用Java config不存在该资源

Get-ChildItem无法找到路径,因为它不存在

无法解析持久性单元根URL:类路径资源[]无法解析为URL,因为它不存在-> [帮助1]

表同步错误。无法删除索引,因为它不存在或您没有权限

MySQL无法从现有表中选择,因为它不存在?

无法发布工件'xxx.aar'(xxx.aar),因为它不存在

未捕获的TypeError:无法读取未定义的属性“ 0”,因为它不存在

无法获得额外扩展名上的属性“ compileSdkVersion”,因为它不存在打开文件