简体   繁体   English

将 Spring MVC 应用程序转换为 Spring Boot - BeanCurrentlyInCreationException 问题

[英]Convert a Spring MVC application to Spring Boot - BeanCurrentlyInCreationException issue

I have a Spring MVC application, using Hibernate for my entities persistence management.我有一个 Spring MVC 应用程序,使用 Hibernate 进行实体持久性管理。 I am able to build, deploy and run it on some application server such as glashfish or tomcat, all is fine.我能够在一些应用程序服务器(如 glashfish 或 tomcat)上构建、部署和运行它,一切都很好。

Now, I want to convert it into a Spring Boot application.现在,我想将其转换为 Spring Boot 应用程序。 I added the following class:我添加了以下类:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext context = 
                            SpringApplication.run(Application.class, args);
    }
}

and added the spring-boot , spring-boot-autoconfigure , and spring-boot-starter-tomcat dependencies to my pom.并将spring-bootspring-boot-autoconfigurespring-boot-starter-tomcat依赖项添加到我的 pom.xml 文件中。

Alas, when trying to run the application, I get the following error:唉,在尝试运行应用程序时,我收到以下错误:

BeanCurrentlyInCreationException: Error creating bean with name
'MyClassDAO': Bean with name 'MyClassDAO' has been injected into 
other beans [MyOtherClassDAO] in its raw version as part of a circular
reference, but has eventually been wrapped. This means that said other
beans do not use the final version of the bean. This is often the result
of over-eager type matching - consider using 'getBeanNamesOfType' with 
the 'allowEagerInit' flag turned off, for example.

I don't know how to use 'getBeanNamesOfType' and set the allowEagerInit off (I do not use XML configuration).我不知道如何使用 'getBeanNamesOfType' 并将allowEagerInit设置为关闭(我不使用 XML 配置)。 Of course, I'm not sure this would solve my issue anyway.当然,我不确定这是否会解决我的问题。

Any ideas on how I can fix this?关于如何解决这个问题的任何想法?

如果这真的是一些初始化问题,那么我相信您必须将您的类放在其他包中,并且由于某些缓存问题,它不包括类路径中的那些类以在容器中进行扫描,因此要手动执行此操作,您可以添加注释@springbootapllication下面是@EnableComponentScan(“输入未初始化的类的包名”)也在那个dao类上放@service或@component注解让应用程序包含然后在容器中

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

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