需要找不到类型 'com.me.app.vo.MyClassVO ' 的 bean
Required a bean of type 'com.me.app.vo.MyClassVO ' that could not be found
我有一个 POJO class 用作 ValueObject class 以在屏幕上显示 DAO 值。在我的服务 class 中,我已经自动连接了 class 对象。当我启动我的应用程序时,出现以下错误。服务 class 带有 @Service 注释,不确定我的 VO class 中缺少什么。我应该用@bean 或其他任何东西来注释它吗?
Parameter 5 of constructor in com.me.app.service.MyServiceImpl required a bean of type 'com.me.app.vo.MyClassVO' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
class 的名称已更改。
您没有提供任何代码,但我假设您在 MyServiceImpl
的构造函数中有一个 MyClassVO
类型的参数
因此 Spring 尝试注入 MyClassVO
类型的 bean。但我假设 MyClassVO
不是 Spring Bean。
所以你有两个选择:
- 删除 MyClassVO,如果它不应该是 Spring Bean
- 通过使用
@Component
注释使 MyClassVO
成为 Spring Bean
由于 VO 通常是 Value Object 的缩写,我认为选项 1 是更好的解决方案。
我有一个 POJO class 用作 ValueObject class 以在屏幕上显示 DAO 值。在我的服务 class 中,我已经自动连接了 class 对象。当我启动我的应用程序时,出现以下错误。服务 class 带有 @Service 注释,不确定我的 VO class 中缺少什么。我应该用@bean 或其他任何东西来注释它吗?
Parameter 5 of constructor in com.me.app.service.MyServiceImpl required a bean of type 'com.me.app.vo.MyClassVO' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
class 的名称已更改。
您没有提供任何代码,但我假设您在 MyServiceImpl
MyClassVO
类型的参数
因此 Spring 尝试注入 MyClassVO
类型的 bean。但我假设 MyClassVO
不是 Spring Bean。
所以你有两个选择:
- 删除 MyClassVO,如果它不应该是 Spring Bean
- 通过使用
@Component
注释使
MyClassVO
成为 Spring Bean
由于 VO 通常是 Value Object 的缩写,我认为选项 1 是更好的解决方案。