Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPLICATION FAILED TO START ”A component required a bean named '***' that could not be found.“ #2014

Closed
prefect1005 opened this issue Nov 29, 2021 · 8 comments · Fixed by #2422

Comments

@prefect1005
Copy link

Bug Report

Which version of ElasticJob did you use?

elasticjob-lite-spring-boot-starter 3.0.1

Which project did you use? ElasticJob-Lite or ElasticJob-Cloud?

ElasticJob-Lite

Actual behavior


APPLICATION FAILED TO START


Description:
A component required a bean named 'myOneOffJobBean' that could not be found.

my config:
elasticjob.jobs.oneOffJob.elasticJobClass=com.example.demo.MyElasticJob
elasticjob.jobs.oneOffJob.jobBootstrapBeanName=myOneOffJobBean
elasticjob.jobs.oneOffJob.shardingTotalCount=3

in controller:
@resource(name = "myOneOffJobBean")
private OneOffJobBootstrap myOneOffJobBean;

Reason analyze (If you can)

in 3.0.0 version is ok
i find
#1810
this issues

and in this merge
0446a5d
JobBootstrapBeans instantiation in afterSingletonsInstantiated

just because of this,in application Controller , the OneOffJobBootstrap has not init.
so what can i do?

hope to reply, thanks

Steps to reproduce the behavior.

Example codes for reproduce this issue (such as a github link).

@DoolinMa
Copy link
Contributor

@prefect1005 you can put @lazy annotation on Controller to make sure the application is running normally

@Lazy
public class OneOffJobController {

@cocodroid
Copy link
Contributor

You can also use @Autowried(required=false) @qualifier("myOneOffJobBean")

@ceylog
Copy link

ceylog commented Jan 30, 2022

I also have the same problem

@kingkh1995
Copy link

kingkh1995 commented Oct 22, 2023

#1930 this fix is the cause of this issue, i think the only solution is lazy init, but OneOffBootStrap is final.

#1810 if we need to autowire OneOffBootStrap, OneOffBootStrap need to be registered before AutowiredAnnotationBeanPostProcessor, so ElasticJobProperties bean need to be initialized before AutowiredAnnotationBeanPostProcessor, which means ElasticJobProperties will be not eligible for getting processed by all BeanPostProcessors.

@linghengqian
Copy link
Member

#1930 this fix is the cause of this issue, i think the only solution is to lazy init, but OneOffBootStrap is final.

@kingkh1995
Copy link

kingkh1995 commented Dec 14, 2023

another way is to use @lookup, is this okay? @linghengqian

@Lookup("onceJobBootstrap")
public OneOffJobBootstrap getOnceJobBootstrap() {
    return null;
}

@linghengqian
Copy link
Member

@linghengqian
Copy link
Member

linghengqian commented Aug 10, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants