Spring:BeanInitializationException: Could not load properties

错误信息:

严重: Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [dbconn.properties] cannot be opened because it does not exist
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

这里查看配置的属性文件如下:
<context:property-placeholder location="classpath:jdbc.properties" />

实际上应该是找不到文件,之前放在Web主目录(WebContent)下,下载放在src目录下能够解决问题或者是配置文件classpath:jdbc.properties写的不对,请仔细检查

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.springframework.beans.factory.BeanInitializationException: Could not load propertiesSpring框架中的一个异常,表示无法加载属性。通常,这个异常会在初始化bean时抛出,可能是因为找不到或无法读取配置文件中的属性值。 在你提供的代码中,这个异常可能是由于无法加载beanLifeCyclebeans.xml配置文件中的属性值导致的。你可以检查一下配置文件的路径是否正确,以及文件中的属性是否正确。 另外,根据你提供的代码,我们可以看到使用了两个不同的Person对象,一个是singleton范围的person2,另一个是prototype范围的person3。singleton范围的bean在容器启动时就会被创建,而prototype范围的bean则是每次请求时都会创建一个新的实例。 在BeanLifeCycle类中,通过ApplicationContext的getBean方法可以获取到指定名称的bean,并进行操作。在你提供的代码中,获取了名为"person3"的bean,并输出了其内容。 最后,在关闭容器时,可以通过ClassPathXmlApplicationContext的registerShutdownHook方法来注册一个关闭钩子,以确保在JVM关闭时正常关闭Spring容器。 综上所述,org.springframework.beans.factory.BeanInitializationException: Could not load properties异常是由于无法加载属性导致的,你需要检查配置文件的路径和属性值是否正确。此外,代码中还展示了使用不同范围的bean以及获取和关闭Spring容器的操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Spring IOC](https://blog.csdn.net/u012270113/article/details/80802914)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值