简体   繁体   中英

Convert a Spring MVC application to Spring Boot - BeanCurrentlyInCreationException issue

I have a Spring MVC application, using Hibernate for my entities persistence management. I am able to build, deploy and run it on some application server such as glashfish or tomcat, all is fine.

Now, I want to convert it into a Spring Boot application. 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.

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). 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注解让应用程序包含然后在容器中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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