繁体   English   中英

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

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

我有一个 Spring MVC 应用程序,使用 Hibernate 进行实体持久性管理。 我能够在一些应用程序服务器(如 glashfish 或 tomcat)上构建、部署和运行它,一切都很好。

现在,我想将其转换为 Spring Boot 应用程序。 我添加了以下类:

@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);
    }
}

并将spring-bootspring-boot-autoconfigurespring-boot-starter-tomcat依赖项添加到我的 pom.xml 文件中。

唉,在尝试运行应用程序时,我收到以下错误:

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.

我不知道如何使用 'getBeanNamesOfType' 并将allowEagerInit设置为关闭(我不使用 XML 配置)。 当然,我不确定这是否会解决我的问题。

关于如何解决这个问题的任何想法?

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

暂无
暂无

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

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