我想在抽象类上有计划注释,以便子类不需要有注释。抽象类中有类似的东西
@EnableScheduling
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
public abstract class AbstractTestClass {
@Bean
public String getDelay() {
return "1000";
}
@Scheduled(fixedRateString = "#{@getDelay}")
public void callScheduledMethod() {
getZeroBytesFile();
}
public abstract void getZeroBytesFile();
}
@Component
public class ChildClass extends AbstractTestClass {
@Override
public String getDelay() {
return "5000";
}
@Override
public void getZeroBytesFile() {
System.out.println("called");
}
}
@Component
public class OtherClass {
// This bean initialisation throws error
@AutoWired ChildClass childClass;
}
但是它不起作用并抛出此异常
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'getDelay': Requested bean is currently in creation: Is there an unresolvable circular reference?
任何指针都会有帮助。提前致谢
最佳答案
这是实现这一目标的技巧:
@EnableScheduling
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
public abstract class AbstractTestClass {
@Bean
public String getDelay() {
return "1000";
}
@Scheduled(fixedRateString = "#{@getDelay}")
public void callScheduledMethod() {
getZeroBytesFile();
}
public abstract void getZeroBytesFile();
}
@Component
public class ChildClass extends AbstractTestClass {
@Override
public String getDelay() {
return "5000";
}
@Override
public void getZeroBytesFile() {
System.out.println("called");
}
}
关于java - 异常: org. springframework.beans.factory.BeanCurrentlyInCreationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59701817/