Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

SPR-17166 @Scheduled tasks run twice on proxied bean #182

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions SPR-17166/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
43 changes: 43 additions & 0 deletions SPR-17166/src/main/java/xxx/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package xxx;

import java.time.Instant;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@SpringBootApplication
@EnableScheduling
public class Application {

@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public static class A {

@Scheduled(fixedDelay = 1000)
public void task() {
System.out.println(Instant.now());
}

}

@Service
public static class B {

private final A a;

B(A a) {
this.a = a;
}

}

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}