当前位置:  开发笔记 > 编程语言 > 正文

Spring @Autowired无法正常工作 - BeanCreationException

如何解决《Spring@Autowired无法正常工作-BeanCreationException》经验,为你挑选了1个好方法。

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

例外

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




beans.xml中



我的错误在哪里?



1> David Tanzer..:

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

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

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

因此,Spring自动装配实际上正在工作,但由于初始化其中一个spring bean时出现数据库问题,因此无法自动连接您的依赖关系.

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

推荐阅读
N个小灰流_701
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有