![](/img/trans.png)
[英]Spring BeanCreationException Injection of autowired dependencies failed
[英]Spring @Autowired not working - 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" />
我的錯誤在哪里?
這是您的異常消息中的最后一個原因
Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is javax.persistence.PersistenceException
Spring無法調用jpaMappingContext
的init方法,因為發生了持久性異常 - 數據庫出錯了。
因此,Spring自動裝配實際上正在工作,但由於初始化其中一個spring bean時出現數據庫問題,因此無法自動連接您的依賴關系。
因此,自上次編碼以來,數據庫或數據庫設置中的某些內容已更改。 分析完整堆棧跟蹤以找出此問題的根本原因 - 這是一個數據庫問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.