2016-03-10 2 views
-1

Я очень новичок в веб-приложениях JAVA, поэтому имейте это в виду. Я взял очень большой проект, это сложно. Я, наконец, получил исправления в Maven и теперь получаю первые ошибки при работе на Tomcat.Spring - Ошибка создания bean

Что означает эта ошибка, пожалуйста? Как исправить исправление?

Что делает Autowired?

Что делает фабрика сеансов Hibernate? Могли ли плохие параметры файла jdbc.properties вникать в все?

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 

Spring Config для модуля, содержащего eu.digient.billfold.goshgame.game.level.ItemConfigFactoryImpl:

<?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> 

+0

Does 'ClassNotFoundException: eu.digient.billfold.goshgame.level.ItemConfigFactoryImpl' что-нибудь для вас значит? Вам не хватает файла jar в вашем пути к классам? Пожалуйста, посетите [помощь], а также прочитайте [ask]. Объяснение того, что такое фабрика сеансов Autowire и Hibernate, выходит далеко за рамки StackOverflow. Эти понятия уже документированы, и вы должны прочитать документацию. –

ответ

0

Существует отличный ответ о том, что есть и что делать @Autowired - Understanding Spring @Autowired usage Я предлагаю вам использовать @Inject вместо @Autowired, потому что @Autowired - это аннотация для Spring. Подробнее можно найти здесь - Inject and Resource and Autowired annotations Я задал аналогичный вопрос о свойствах и создании bean-компонента с @autowired: Connection to database with JdbcTemplate Возможно, проблема с bean-компонентами связана с вашими свойствами (.properties или .xml).

Да, весна явно не нашла класс, который вы ищете. Вы можете попытаться выполнить поиск в целевом каталоге.

+0

Класс есть, возможно, это отсутствие настроек конфигурации пружины. Все эти ссылки были полезны. Текст терминологии JAVA убивает меня, но теперь я начинаю приписывать понятия терминологии JAVA, которая является жестким. Так что @Inject обходит ошибки? – Beloudest

+0

Нет, это очень похоже на @Autowired, но поскольку это java-подход к настройке, ваше приложение более гибкое и зависит не только от Spring. Чтобы попытаться исправить это, вы можете проверить файл spring.xml. Должно быть что-то вроде: ' '. Дополнительную информацию можно найти здесь - http://docs.spring.io/spring-javaconfig/docs/1.0.0.m3/reference/html/creating-bean-definitions.html –

+0

Да, это я в конфиге. Я редактировал конфигурацию Spring в вопросе выше, кажется, все в порядке. Теперь я рассмотрю настройки .properties. – Beloudest

0

Это говорит ClassNotFoundException: eu.digient.billfold.goshgame.game .level.ItemConfigFactoryImpl

Проверьте, присутствует ли этот класс в файле конфигурации пружин

+0

Привет, я проверил конфигурацию, и все выглядит нормально? Как вы думаете, я добавил его к моему вопросу. – Beloudest

+0

Дело в том, что после прочтения вашей конфигурации он попытается инициализировать этот класс. Убедитесь, что этот класс существует в вашем пути к классам. Сделайте ctrl + Shift + T, напишите имя класса. Проверьте правильность пакета и имя класса. –

Смежные вопросы