2016-01-12 4 views
4

При попытке развернуть файл на сервере возникает ошибка. Я смущен, потому что этот код работал.Spring @Autowired не работает - BeanCreationException

Исключение

Failed to enable lec2ear-1.0.ear. 

Unexpected HTTP response: 500 

Request 
{ 
    "address" => [("deployment" => "lecture_7")], 
    "operation" => "deploy" 
} 

Response 

Internal Server Error 
{ 
    "outcome" => "failed", 
    "failure-description" => {"JBAS014671: Failed services" => {"jboss.undertow.deployment.default-server.default-host./mart-parent" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./mart-parent: Failed to start service 
    Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storageController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ru.menkin.ea.lec4.model.services.ICategoryService ru.menkin.ea.lec5.controllers.StorageController._categoryService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ru.menkin.ea.lec4.model.repositories.CategoryRepository ru.menkin.ea.lec4.model.services.CategoryService.categoryRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryRepository': Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/recipeDs 
Error Code: 0 

ICategoryService

public interface ICategoryService 
{ 
    public Category create(Category category); 
    public Category delete(int id) throws Exception; 
    public List<Category> findAll(); 
    public Category update(Category category) throws Exception; 
    public Category findById(int id); 
} 

его реализация

public class CategoryService implements ICategoryService 
{ 
    @Autowired 
    private CategoryRepository categoryRepository; 
... 

Контроллер

@Controller 
@RequestMapping(value = "/rest") 
public class StorageController extends BaseController { 
    @Autowired 
    @Qualifier("categoryService") 
    private ICategoryService _categoryService; 
... 

database.xml

<djpa:repositories base-package="ru.menkin.ea.lec4.model" /> 

<bean id="categoryService" class="ru.menkin.ea.lec4.model.services.CategoryService" /> 

beans.xml

<context:annotation-config /> 
<context:component-scan base-package="ru.menkin.ea" /> 

Где моя ошибка?

+1

Опубликовать полный stacktrae. –

+1

Является ли 'CategoryService' аннотированным' @ Service'? – Jens

+0

Теперь нет, но я пытаюсь добавить эту аннотацию. –

ответ

5

Вот последняя причина в вашем сообщении исключение:

Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException 

Spring не может вызвать метод инициализации вашего jpaMappingContext, поскольку исключение живучесть произошло - что-то пошло не так в базе данных.

Итак, весна autowiring на самом деле работает, но она не может автоувеличивать вашу зависимость из-за проблемы с базой данных, которая возникает при инициализации одного из весенних боб.

Так что-то в настройках базы данных или базы данных изменилось с момента последнего использования этого кода. Проанализируйте полную трассировку стека, чтобы узнать основную причину этой проблемы. Это проблема с базой данных.

+1

Спасибо. Проблема связана с подключением к базе данных. Работает Autowired.)) –

+0

David - Не могли бы вы посоветуете http://stackoverflow.com/questions/35685804/how-to-make-database-configuration-configurable-of-persistance-xml-file-through? – Prateek

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