如何使实体成为spring mvc中的托管类型 [英] How to make an entity be a managed type in spring mvc

查看:149
本文介绍了如何使实体成为spring mvc中的托管类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Apache Tomcat运行Spring应用程序,并在服务器日志中收到以下异常:

[ Apache Log] org.springframework.beans.factory.BeanCreationException:创建bean wi时出错 - Pastebin.com [ ^ ]



在日志中它最后说它是由实体分配不是托管类型引起的。



以下是实体:

[Java]包com.mihaib.springmvc .entities; import javax.persistence。*; import ja - Pastebin.com [ ^ ]



我正在使用Hibernate进行数据库映射。

我在另一个论坛上看到有人说这是由于课堂上缺少@Entity注释。我有注释,但我仍然得到例外。



如何使实体成为托管类型或我可以做些什么来解决此异常。

I am trying to run a Spring application with Apache Tomcat and I get the following exception in the server log:
[Apache Log] org.springframework.beans.factory.BeanCreationException: Error creating bean wi - Pastebin.com[^]

In the log it says at the end that it is caused by entity Assignment not being a managed type.

Here is the entity:
[Java] package com.mihaib.springmvc.entities; import javax.persistence.*; import ja - Pastebin.com[^]

I am using Hibernate for database mapping.
I saw on another forum that someone said that it was due to a missing @Entity annotation on the class. I have the annotation, but I still get the exception.

How can I make the entity be a managed type or what else I can do to resolve this exception.

推荐答案

我认为问题出在注入时。你可以在日志中看到

创建名为'assignmentController'的bean时出错:注入自动连接的依赖项失败;



可能是你试图将服务类注入到控制器类那里你遇到了问题,DAO课程中的问题不在于你的日志清楚。



引起:无法自动装配字段:private com.mihaib.springmvc.services.AssignmentService com.mihaib.springmvc.controller.AssignmentController。





如果可能发布你的控制器和服务类,@ autowired问题即注入问题
I think the problem is while injecting. you can see in log
Error creating bean with name 'assignmentController': Injection of autowired dependencies failed;

may be you are trying to injecting service class to controller class there you are getting a problem, problem is not in DAO class see your log clearly.

Caused by: Could not autowire field: private com.mihaib.springmvc.services.AssignmentService com.mihaib.springmvc.controller.AssignmentController.


If possible post your controller and service class, problem with @autowired i.e injection problem


这篇关于如何使实体成为spring mvc中的托管类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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