Can ApplicationContext.getBean() get the RequestScope bean correctly?

Viewed 20

I need to use below RequestScope bean in some integration. Autowired doesn't work in the integration. Now I use ApplicationContext.getBean to get it.

@Component
@RequestScope
@Data
public class MyRequestBean{

    public int random() {
        return random;
    }
}


@Component
public class SomeTask implements SomeIntegrationJavaDelegate {

 //Autowired doesn't work
 private MyRequestBean myRequestBean = ApplicationContext.getBean(MyRequestBean.class);
}

It works for singleton bean. Will it have any problem on RequestScope bean? How does it get correct RequestScope bean?

1 Answers

Try @Resource instead of @Autowired.

Related