Skip to content

Commit 108a39d

Browse files
committed
Refactor Application class with Spring Data and Swagger documentation
1 parent 91a64f6 commit 108a39d

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
package org.couchbase.quickstart.springdata;
22

3+
import org.springframework.boot.CommandLineRunner;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
57
import org.springframework.context.annotation.Bean;
68
import org.springframework.web.filter.ForwardedHeaderFilter;
79

10+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
11+
import io.swagger.v3.oas.annotations.info.Info;
12+
import lombok.extern.slf4j.Slf4j;
13+
814
/**
915
* This example application demonstrates using
1016
* Spring Data with Couchbase.
1117
**/
12-
@SpringBootApplication
13-
public class Application {
1418

15-
public static void main(String[] args) {
16-
SpringApplication.run(Application.class, args);
17-
}
19+
@Slf4j
20+
@SpringBootApplication(exclude = SecurityAutoConfiguration.class, proxyBeanMethods = false)
21+
@OpenAPIDefinition(info = @Info(title = "Quickstart in Couchbase with Spring Data", version = "2.0", description = "<html><body><h2>A quickstart API using Java and Spring Data with Couchbase and travel-sample data</h2><p>We have a visual representation of the API documentation using Swagger which allows you to interact with the API's endpoints directly through the browser. It provides a clear view of the API including endpoints, HTTP methods, request parameters, and response objects.</p><p>Click on an individual endpoint to expand it and see detailed information. This includes the endpoint's description, possible response status codes, and the request parameters it accepts.</p><p><strong>Trying Out the API</strong></p><p>You can try out an API by clicking on the \"Try it out\" button next to the endpoints.</p><ul><li><strong>Parameters:</strong> If an endpoint requires parameters, Swagger UI provides input boxes for you to fill in. This could include path parameters, query strings, headers, or the body of a POST/PUT request.</li><li><strong>Execution:</strong> Once you've inputted all the necessary parameters, you can click the \"Execute\" button to make a live API call. Swagger UI will send the request to the API and display the response directly in the documentation. This includes the response code, response headers, and response body.</li></ul><p><strong>Models</strong></p><p>Swagger documents the structure of request and response bodies using models. These models define the expected data structure using JSON schema and are extremely helpful in understanding what data to send and expect.</p><p>For details on the API, please check the tutorial on the Couchbase Developer Portal: <a href=\"https://developer.couchbase.com/tutorial-quickstart-java-spring-boot\">https://developer.couchbase.com/tutorial-quickstart-java-spring-boot</a></p></body></html>"))
22+
public class Application implements CommandLineRunner {
23+
24+
@Override
25+
public void run(String... args) throws Exception {
26+
log.info("Application started successfully");
27+
}
28+
public static void main(String[] args) {
29+
SpringApplication.run(Application.class, args);
30+
}
31+
32+
33+
@Bean
34+
ForwardedHeaderFilter forwardedHeaderFilter() {
35+
return new ForwardedHeaderFilter();
36+
}
37+
1838

19-
@Bean
20-
ForwardedHeaderFilter forwardedHeaderFilter() {
21-
return new ForwardedHeaderFilter();
22-
}
2339
}

0 commit comments

Comments
 (0)