简体   繁体   English

Spring Boot CRUD应用程序-找不到Bean错误

[英]Spring boot CRUD application - Bean not found error

I am developing a simple CRUD application with spring-boot. 我正在用spring-boot开发一个简单的CRUD应用程序。

I have most of the project completed, although I get this error when I try to run the project. 我已经完成了大部分项目,尽管在尝试运行该项目时出现此错误。

Description: 描述:

Field userDBOP in com.application.crud.GreetingController required a bean of type 'com.application.crud.myoperation.JdbcUserDAO' that could not be found. com.application.crud.GreetingController中的字段userDBOP需要一个类型为com.application.crud.myoperation.JdbcUserDAO的bean。

Action: 行动:

Consider defining a bean of type 'com.application.crud.myoperation.JdbcUserDAO' in your configuration. 考虑在您的配置中定义类型为“ com.application.crud.myoperation.JdbcUserDAO”的bean。

In IntelliJ when I hover over the line that causes the error, the following message shows up 在IntelliJ中,当我将鼠标悬停在导致错误的行上时,将显示以下消息

"Could not autowire. No beans of 'JdbcUserDAO' type found. “无法自动装配。找不到'JdbcUserDAO'类型的bean。

Even though I have in my 'Beans.xml' file (located below the 'src' directory: 即使我在“ Beans.xml”文件中(位于“ src”目录下面:

<bean id="customerDAO" class="com.application.crud.myoperation.JdbcUserDAO">
    <property name="dataSource" ref="dataSource" />
</bean>

Can anyone tell me how to fix this error? 谁能告诉我如何解决此错误?

This seems to be a problem with configuring a Spring Boot Application with an existing Spring Context . 使用现有的Spring Context配置Spring Boot Application似乎是一个问题。 There is a section in the Spring documentation about this. Spring文档中有一节对此进行了说明。

By default, you need to specify the location of your application context using the @ImportResource annotation. 默认情况下,您需要使用@ImportResource批注指定应用程序上下文的位置。 An example would be: 一个例子是:

@SpringBootApplication
@ImportResource("applicationContext.xml")
public class ExampleApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(ExampleApplication.class, args);
    }

}

Note that if the file is located elsewhere in the classpath, then you need to reference it properly for spring to pick it up (eg @ImportResource({"classpath*:applicationContext.xml"}) ) 请注意 ,如果文件位于类路径中的其他位置,那么您需要正确地引用该文件以供Spring拾取(例如@ImportResource({"classpath*:applicationContext.xml"})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM