Spring @Autowired无法正常工作-BeanCreationException [英] Spring @Autowired not working - BeanCreationException

查看:146
本文介绍了Spring @Autowired无法正常工作-BeanCreationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在服务器上部署文件时发生错误.我很困惑,因为这段代码可以正常工作.

When I try to deploy file on server error occurs. I'm confused, because this code was working.

例外

    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" />

我的错误在哪里?

推荐答案

这是您的异常消息中的最后一个原因:

Here last cause in your exception message:

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

Spring无法调用 jpaMappingContext 的init方法,因为发生了持久性异常-数据库出了点问题.

Spring could not invoke the init method of your jpaMappingContext because a persistence exception occured - Something went wrong in the database.

因此,Spring自动装配实际上是有效的,但是由于初始化一个Spring Bean时发生数据库问题,它无法自动装配依赖关系.

So, Spring autowiring is actually working, but it cannot autowire your dependency because of a database problem that occurs when initializing one of the spring beans.

因此,自该代码上次生效以来,数据库或数据库设置中的某些内容发生了更改.分析整个堆栈跟踪以找出此问题的根本原因-这是数据库问题.

So something in the database or database settings changed since this code last worked. Analyze the full stack trace to find out the root cause of this issue - Which is a database problem.

这篇关于Spring @Autowired无法正常工作-BeanCreationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆