Skip to content

Commit

Permalink
fix(startup): make constructor bean optional (#2247)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored Dec 21, 2017
1 parent b96b579 commit 6ee3a95
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Slf4j
@RestController
@RequestMapping("/artifacts")
public class ArtifactController {
private ArtifactCredentialsRepository artifactCredentialsRepository;

@Autowired(required = false)
public ArtifactController(ArtifactCredentialsRepository artifactCredentialsRepository) {
this.artifactCredentialsRepository = artifactCredentialsRepository;
@Autowired
public ArtifactController(Optional<ArtifactCredentialsRepository> artifactCredentialsRepository) {
this.artifactCredentialsRepository = artifactCredentialsRepository.orElse(null);
}

@RequestMapping(method = RequestMethod.GET, value = "/credentials")
List<ArtifactCredentials> list() {
return artifactCredentialsRepository.getAllCredentials();
if (artifactCredentialsRepository == null) {
return new ArrayList<>();
} else {
return artifactCredentialsRepository.getAllCredentials();
}
}
}

0 comments on commit 6ee3a95

Please sign in to comment.