Open
Description
This is how I use it now
try(GitLabApi gitLabApi = new GitLabApi(rootUrl, param.getGitlabToken())) {
MergeRequestParams mrParams = new MergeRequestParams()
.withSourceBranch(param.getSourceBranch())
.withTargetBranch(param.getTargetBranch())
.withTitle(param.getTitle())
.withDescription(param.getDescription())
.withLabels(param.getLabels());
MergeRequest mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(param.getGitProjectId().longValue(), mrParams);
return GitlabFormatUtils.buildGitlabMergeRequest(mergeRequest);
} catch (GitLabApiException e) {
log.error("创建MergeRequest失败,param:{}", param, e);
throw new ServiceException("创建gitlab MergeRequest失败");
}
I want to change it to the following, but I am worried about thread safety issues
@Configuration
public class GitLabSdkConfig {
@Value("${gitlab.rootUrl}")
private String rootUrl;
@Value("${gitlab.devopsToken}")
private String devopsToken;
@Bean
public GitLabApi initGitLabApi() {
return new GitLabApi(rootUrl, devopsToken);
}
}
@Resource
private GitLabApi gitLabApi;
try {
MergeRequestParams mrParams = new MergeRequestParams()
.withSourceBranch(param.getSourceBranch())
.withTargetBranch(param.getTargetBranch())
.withTitle(param.getTitle())
.withDescription(param.getDescription())
.withLabels(param.getLabels());
MergeRequest mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(param.getGitProjectId().longValue(), mrParams);
return GitlabFormatUtils.buildGitlabMergeRequest(mergeRequest);
} catch (GitLabApiException e) {
log.error("创建MergeRequest失败,param:{}", param, e);
throw new ServiceException("创建gitlab MergeRequest失败");
}
thanks for your answer