Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Use ObjectProvider instead of @lazy
Browse files Browse the repository at this point in the history
Spring AOT (used to help Java native build) does not
recognize proxies created by proxy. Use ObjectProvider instead.
It is recommended anyway (even if no Java native build is used).

See spring-projects/spring-framework#29584
  • Loading branch information
plamentotev committed Nov 19, 2023
1 parent 073bdef commit d11988b
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import mosquitobytes.carboncritters.model.Profile;
import mosquitobytes.carboncritters.model.Score;
import mosquitobytes.carboncritters.repository.ProfileRepository;
import org.springframework.context.annotation.Lazy;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;

import java.io.IOException;
Expand All @@ -15,12 +16,12 @@
@Service
public class ProfileService {

private final CustomWebSocketHandler webSocketHandler;
private final ObjectProvider<CustomWebSocketHandler> webSocketHandlerProvider;

private final ProfileRepository profileRepository;

public ProfileService(@Lazy CustomWebSocketHandler webSocketHandler, ProfileRepository profileRepository) {
this.webSocketHandler = webSocketHandler;
public ProfileService(ObjectProvider<CustomWebSocketHandler> webSocketHandlerProvider, ProfileRepository profileRepository) {
this.webSocketHandlerProvider = webSocketHandlerProvider;
this.profileRepository = profileRepository;
}

Expand Down Expand Up @@ -53,6 +54,7 @@ public void resetScore() {
profiles.forEach(this::resetScore);

try {
var webSocketHandler = webSocketHandlerProvider.getIfAvailable();
webSocketHandler.sendLeaderBoardToAllActiveSessions();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit d11988b

Please sign in to comment.