簡體   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