当Im使用@Component注释而不使用任何@Autowired时,我正在尝试使用springs @Async处理;当Im在组件中使用@Autowired来获取其他bean时,我正在尝试使用
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'asyncComp': Bean with name 'asyncComp' has been injected into other beans [containerService] 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.
TestClass{
static AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
public static void main( String[] args ) throws SchedulerException
{
ContainerServiceLocal containerService = (ContainerServiceLocal) context.getBean("containerService");
containerService.printAsync();
}
}
@Service("containerService")
@Transactional
public class ContainerService implements ContainerServiceLocal {
@Autowired
AsyncCompLocal comp;
public void printAsync(){
comp.backgroudProcessing();
}
}
@Component
public class AsyncComp implements AsyncCompLocal{
@Autowired
ContainerServiceLocal containerService;
@Async
@Override
public void backgroudProcessing() {
for(int i=0;i<10;i++){
System.out.println("Backgroud processing");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public interface AsyncCompLocal {
public void backgroudProcessing();
}