如何将原型bean注入单例bean中?
我得到了预期的结果。我只想知道这是在Spring Boot中执行此操作的正确方法还是有更好的方法?
我每次需要调用方法m1();时都需要类HelloWorld的新实例。
@Service
@Scope("prototype")
public class HelloWorld{
....
..
}
@Service
Class Job
@Autowired
private WebApplicationContext context;
public void m1( )
{
HelloWorldobj = (HelloWorld) context.getBean("helloWorld");
.......
...
}
@Component
@EnableScheduling
class MyScheduler
{
@Autowire
Job job;
@Scheduled(fixedDelay = 2000)
void taskMethod( )
{
job.m1();
}