我正在使用@ConfigurationProperties来定义属性my.delay。
@ConfigurationProperties( "my" )
public class MyProperties {
private long delay = 1000L;
public long getDelay() {
return delay;
}
public void setDelay(long delay) {
this.delay = delay;
}
}
Run Code Online (Sandbox Code Playgroud)
在调度程序方法中,我尝试使用my.delay:
@SpringBootApplication
@EnableScheduling
@EnableConfigurationProperties( { MyProperties.class } )
public class TestSprPropApplication {
public static void main(String[] args) {
SpringApplication.run(TestSprPropApplication.class, args);
}
@Scheduled( fixedDelayString = "${my.delay}" )
public void schedule() {
System.out.println( "scheduled" );
}
}
Run Code Online (Sandbox Code Playgroud)
然后出现以下错误:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'schedule': Could not …Run Code Online (Sandbox Code Playgroud)