Skip to content

Commit f5b17a6

Browse files
committed
use initializing bean instead of postconstruct
1 parent 04f5043 commit f5b17a6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

springdoc-openapi-ui/src/main/java/org/springdoc/ui/SwaggerWelcome.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.commons.lang3.StringUtils;
55
import org.springdoc.core.OpenAPIBuilder;
66
import org.springdoc.core.SwaggerUiConfigProperties;
7+
import org.springframework.beans.factory.InitializingBean;
78
import org.springframework.beans.factory.annotation.Autowired;
89
import org.springframework.beans.factory.annotation.Value;
910
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -15,7 +16,6 @@
1516
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
1617
import org.springframework.web.util.UriComponentsBuilder;
1718

18-
import javax.annotation.PostConstruct;
1919
import javax.servlet.http.HttpServletRequest;
2020
import java.util.Map;
2121

@@ -26,7 +26,7 @@
2626
@Controller
2727
@ConditionalOnProperty(name = SPRINGDOC_SWAGGER_UI_ENABLED, matchIfMissing = true)
2828
@ConditionalOnBean(OpenAPIBuilder.class)
29-
class SwaggerWelcome {
29+
class SwaggerWelcome implements InitializingBean {
3030

3131
@Value(API_DOCS_URL)
3232
private String apiDocsUrl;
@@ -42,8 +42,13 @@ class SwaggerWelcome {
4242

4343
private String uiRootPath;
4444

45-
@PostConstruct
46-
public void calculateUiRootPath() {
45+
46+
@Override
47+
public void afterPropertiesSet() {
48+
calculateUiRootPath();
49+
}
50+
51+
private void calculateUiRootPath() {
4752
StringBuilder sbUrl = new StringBuilder();
4853
if (StringUtils.isNotBlank(mvcServletPath))
4954
sbUrl.append(mvcServletPath);
@@ -95,4 +100,4 @@ private void buildConfigUrl(HttpServletRequest request) {
95100
}
96101
}
97102

98-
}
103+
}

0 commit comments

Comments
 (0)