当前位置: 首页 > 知识库问答 >
问题:

Spring错误创建bean

程志新
2023-03-14

我对JAVA web应用程序非常陌生,所以请记住这一点。我承担了一个非常大的项目,令人望而生畏。我终于修复了Maven依赖,现在在Tomcat上运行时遇到了第一个错误。

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'billfoldApplicationDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void eu.digient.billfold.support.dao.AbstractBaseDao.init(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl] for bean with name 'itemConfigFactoryImpl' defined in URL [jar:file:/Users/Stu/Development/EclipseFresh/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/crazyowls-demo-web/WEB-INF/lib/crazyowls-game-1.0-SNAPSHOT.jar!/ctx-grazyowl-game.xml]; nested exception is java.lang.ClassNotFoundException: eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void eu.digient.billfold.support.dao.AbstractBaseDao.init(org.hibernate.SessionFactory); nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl] for bean with name 'itemConfigFactoryImpl' defined in URL [jar:file:/Users/Stu/Development/EclipseFresh/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/crazyowls-demo-web/WEB-INF/lib/crazyowls-game-1.0-SNAPSHOT.jar!/ctx-grazyowl-game.xml]; nested exception is java.lang.ClassNotFoundException: eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:604)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 22 more
 Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl] for bean with name 'itemConfigFactoryImpl' defined in URL [jar:file:/Users/Stu/Development/EclipseFresh/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/crazyowls-demo-web/WEB-INF/lib/crazyowls-game-1.0-SNAPSHOT.jar!/ctx-grazyowl-game.xml]; nested exception is java.lang.ClassNotFoundException: eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1281)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1350)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:355)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:334)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:897)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
... 24 more
 Caused by: java.lang.ClassNotFoundException: eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:255)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1302)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1273)
... 33 more

包含eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl模块的Spring配置:

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.1.xsd
                       http://www.springframework.org/schema/util
                       http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<context:annotation-config />

<context:component-scan base-package="eu.digient.billfold.goshgame.game"/>

<context:property-placeholder properties-ref="goshgameProperties" ignore-unresolvable="true" />
<util:properties id="goshgameProperties" location="classpath:goshgame.properties" />

<bean id="itemConfigFactoryImpl" class="eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl">
    <property name="properties" ref="goshgameProperties"/>
</bean>

共有1个答案

岑俊明
2023-03-14

关于@autowired是什么和做什么,有一个很好的答案-了解Spring@autowired的用法我建议您使用@inject而不是@autowired,因为@autowired是Spring特定的注释。这里可以找到更多信息--注入、资源和Autowired注释我问过类似的关于属性和使用@Autowired创建bean的问题:使用JdbcTemplate连接到数据库bean可能bean的问题在于您的属性(.properties或.xml)文件。

是的,spring显然没有找到您正在搜索的类。您可以尝试在目标目录中搜索它。

 类似资料:
  • 问题内容: 知道为什么我会收到这个例外吗? 问题答案: 我怀疑如果是接口(是吗?),您将不会遇到此错误。我相信您可能有一个正在使用cglib代理,执行魔术等操作的类,最后,它不能安全地转换为setter或构造函数中的参数。尝试对接口进行编程,看看错误是否消失。 更新 :不是接口。这是一个扩展的类。 鉴于此,我建议您尝试以下操作: 重命名为。 从已命名的接口中提取一个接口(例如“ ”) 浏览所有使用

  • 我不能运行Springeureka服务器,我得到以下错误。 组织。springframework。豆。工厂UnsatifiedPendencyException:创建名为“org”的bean时出错。springframework。云netflix。尤里卡。EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration:通过字段“

  • person.java PersonRepository.java PersonService.java PersonController.java MyWebInitializer.java WebConfig.java rootconfig.java Build.Gradle 构建此项目时没有错误,但当我尝试运行此应用程序时,控制台显示错误: 错误org.springframework.web

  • 我使用的是Spring 3.1.4 服务实现 DAO实现 web.xml

  • MySQL说:文档 1064年的今天,您的SQL语法出现错误;查看与您的MariaDB服务器版本对应的手册,了解第2行“@id INT AS BEGIN SET NO COUNT ON”附近使用的正确语法

  • 代码: 导致"ValueError:具有多个元素的数组的真值不明确。使用a.any()或a.all()” 有什么问题?