Skip to content

Commit 640f598

Browse files
author
Siamak Khoubyari
committed
Upgrade Spring Boot to 1.5.6 and upgrade related dependencies;
Upgrade to Swagger2; Add rotating log file boot_example.log; Cleanups
1 parent 5ef3ef5 commit 640f598

File tree

8 files changed

+194
-166
lines changed

8 files changed

+194
-166
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ dependency-reduced-pom.xml
1010
*.ipr
1111
*.iws
1212
*.idea
13+
*.log
1314
Thumbs.db

pom.xml

Lines changed: 135 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,138 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
6-
<groupId>com.khoubyari</groupId>
7-
<artifactId>spring-boot-rest-example</artifactId>
8-
<version>0.3.0</version>
9-
<packaging>war</packaging>
10-
<description>Example project demonstrating REST APIs implemented using Spring Boot, in-memory database, embedded Tomcat, Swagger, JsonPath, Hamcrest and MockMVC</description>
11-
12-
<parent>
13-
<groupId>org.springframework.boot</groupId>
14-
<artifactId>spring-boot-starter-parent</artifactId>
15-
<version>1.3.3.RELEASE</version>
16-
</parent>
17-
18-
<properties>
19-
<start-class>com.khoubyari.example.Application</start-class>
20-
</properties>
21-
22-
<dependencies>
23-
24-
<dependency>
25-
<groupId>org.springframework.boot</groupId>
26-
<artifactId>spring-boot-actuator</artifactId>
27-
</dependency>
28-
29-
<!-- web development, including Tomcat and spring-webmvc -->
30-
<dependency>
31-
<groupId>org.springframework.boot</groupId>
32-
<artifactId>spring-boot-starter-web</artifactId>
33-
</dependency>
34-
35-
<!-- Spring security -->
36-
<dependency>
37-
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter-security</artifactId>
39-
</dependency>
40-
41-
<dependency>
42-
<groupId>org.springframework.boot</groupId>
43-
<artifactId>spring-boot-starter-tomcat</artifactId>
44-
<scope>provided</scope>
45-
</dependency>
46-
47-
<!-- spring-data-jpa, spring-orm and Hibernate -->
48-
<dependency>
49-
<groupId>org.springframework.boot</groupId>
50-
<artifactId>spring-boot-starter-data-jpa</artifactId>
51-
</dependency>
52-
53-
<dependency>
54-
<groupId>com.h2database</groupId>
55-
<artifactId>h2</artifactId>
56-
<version>1.4.181</version>
57-
</dependency>
58-
59-
<!-- spring-test, hamcrest, ... -->
60-
<dependency>
61-
<groupId>org.springframework.boot</groupId>
62-
<artifactId>spring-boot-starter-test</artifactId>
63-
<scope>test</scope>
64-
</dependency>
65-
66-
<dependency>
67-
<groupId>com.fasterxml.jackson.core</groupId>
68-
<artifactId>jackson-databind</artifactId>
69-
</dependency>
70-
71-
<!-- attribute level json comparisons -->
72-
<dependency>
73-
<groupId>com.jayway.jsonpath</groupId>
74-
<artifactId>json-path</artifactId>
75-
<version>0.9.1</version>
76-
<scope>test</scope>
77-
</dependency>
78-
<dependency>
79-
<groupId>com.jayway.jsonpath</groupId>
80-
<artifactId>json-path-assert</artifactId>
81-
<version>0.9.1</version>
82-
<scope>test</scope>
83-
</dependency>
84-
85-
<!-- integration with Swagger API doc generation http://goo.gl/J5FQDM -->
86-
<dependency>
87-
<groupId>com.mangofactory</groupId>
88-
<artifactId>swagger-springmvc</artifactId>
89-
<version>0.8.5</version>
90-
</dependency>
91-
92-
<dependency>
93-
<groupId>org.hsqldb</groupId>
94-
<artifactId>hsqldb</artifactId>
95-
<scope>runtime</scope>
96-
</dependency>
97-
</dependencies>
98-
99-
<build>
100-
<resources>
101-
<resource>
102-
<directory>src/main/resources</directory>
103-
<filtering>true</filtering>
104-
</resource>
105-
</resources>
106-
<plugins>
107-
<plugin>
108-
<groupId>org.apache.maven.plugins</groupId>
109-
<artifactId>maven-compiler-plugin</artifactId>
110-
<version>3.1</version>
111-
<configuration>
112-
<source>1.7</source>
113-
<target>1.7</target>
114-
</configuration>
115-
</plugin>
116-
<!-- Spring boot support -->
117-
<plugin>
118-
<groupId>org.springframework.boot</groupId>
119-
<artifactId>spring-boot-maven-plugin</artifactId>
120-
<configuration>
121-
<addResources>false</addResources>
122-
</configuration>
123-
</plugin>
124-
</plugins>
125-
</build>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.khoubyari</groupId>
7+
<artifactId>spring-boot-rest-example</artifactId>
8+
<version>0.4.0</version>
9+
<packaging>war</packaging>
10+
<description>Example project demonstrating REST APIs implemented using Spring Boot, in-memory database, embedded Tomcat, Swagger, JsonPath, Hamcrest and MockMVC</description>
11+
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>1.5.6.RELEASE</version>
16+
</parent>
17+
18+
<properties>
19+
<start-class>com.khoubyari.example.Application</start-class>
20+
</properties>
21+
22+
<dependencies>
23+
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-actuator</artifactId>
27+
</dependency>
28+
29+
<!-- web development, including Tomcat and spring-webmvc -->
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-web</artifactId>
33+
</dependency>
34+
35+
<!-- Spring security -->
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-security</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-tomcat</artifactId>
44+
<scope>provided</scope>
45+
</dependency>
46+
47+
<!-- spring-data-jpa, spring-orm and Hibernate -->
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-data-jpa</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>com.h2database</groupId>
55+
<artifactId>h2</artifactId>
56+
<version>1.4.193</version>
57+
</dependency>
58+
59+
<!-- spring-test, hamcrest, ... -->
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-test</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
66+
<!-- <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId>
67+
</dependency> -->
68+
<dependency>
69+
<groupId>org.codehaus.jackson</groupId>
70+
<artifactId>jackson-core-asl</artifactId>
71+
<version>1.9.13</version>
72+
</dependency>
73+
<!-- <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jdk8</artifactId>
74+
<version>2.8.7</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId>
75+
<artifactId>jackson-datatype-jsr310</artifactId> <version>2.8.7</version>
76+
</dependency> -->
77+
78+
<!-- attribute level json comparisons -->
79+
<dependency>
80+
<groupId>com.jayway.jsonpath</groupId>
81+
<artifactId>json-path</artifactId>
82+
<version>2.4.0</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>com.jayway.jsonpath</groupId>
86+
<artifactId>json-path-assert</artifactId>
87+
<version>0.9.1</version>
88+
<scope>test</scope>
89+
</dependency>
90+
91+
<!-- integration with Swagger API doc generation http://goo.gl/J5FQDM -->
92+
<!-- integration with Swagger API doc generation http://goo.gl/J5FQDM -->
93+
<dependency>
94+
<groupId>io.springfox</groupId>
95+
<artifactId>springfox-swagger2</artifactId>
96+
<version>2.5.0</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>io.springfox</groupId>
100+
<artifactId>springfox-swagger-ui</artifactId>
101+
<version>2.5.0</version>
102+
</dependency>
103+
104+
<dependency>
105+
<groupId>org.hsqldb</groupId>
106+
<artifactId>hsqldb</artifactId>
107+
<scope>runtime</scope>
108+
</dependency>
109+
</dependencies>
110+
111+
<build>
112+
<resources>
113+
<resource>
114+
<directory>src/main/resources</directory>
115+
<filtering>true</filtering>
116+
</resource>
117+
</resources>
118+
<plugins>
119+
<plugin>
120+
<groupId>org.apache.maven.plugins</groupId>
121+
<artifactId>maven-compiler-plugin</artifactId>
122+
<version>3.1</version>
123+
<configuration>
124+
<source>1.8</source>
125+
<target>1.8</target>
126+
</configuration>
127+
</plugin>
128+
<!-- Spring boot support -->
129+
<plugin>
130+
<groupId>org.springframework.boot</groupId>
131+
<artifactId>spring-boot-maven-plugin</artifactId>
132+
<configuration>
133+
<addResources>false</addResources>
134+
</configuration>
135+
</plugin>
136+
</plugins>
137+
</build>
126138
</project>

src/main/java/com/khoubyari/example/Application.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package com.khoubyari.example;
22

3-
import com.mangofactory.swagger.plugin.EnableSwagger;
43
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
65
import org.springframework.boot.SpringApplication;
76
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
88
import org.springframework.boot.builder.SpringApplicationBuilder;
9-
import org.springframework.boot.context.web.SpringBootServletInitializer;
9+
import org.springframework.boot.web.support.SpringBootServletInitializer;
1010
import org.springframework.context.annotation.ComponentScan;
11+
import org.springframework.context.annotation.Configuration;
1112
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
1213

14+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
15+
1316
/*
1417
* This is the main Spring Boot application class. It configures Spring Boot, JPA, Swagger
1518
*/
1619

20+
@SpringBootApplication
21+
@Configuration
1722
@EnableAutoConfiguration // Sprint Boot Auto Configuration
1823
@ComponentScan(basePackages = "com.khoubyari.example")
1924
@EnableJpaRepositories("com.khoubyari.example.dao.jpa") // To segregate MongoDB and JPA repositories. Otherwise not needed.
20-
@EnableSwagger // auto generation of API docs
2125
public class Application extends SpringBootServletInitializer {
2226

2327
private static final Class<Application> applicationClass = Application.class;
@@ -31,5 +35,6 @@ public static void main(String[] args) {
3135
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
3236
return application.sources(applicationClass);
3337
}
38+
3439

3540
}

src/main/java/com/khoubyari/example/RestControllerAspect.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
@Component
1515
public class RestControllerAspect {
1616

17+
protected final Logger log = LoggerFactory.getLogger(this.getClass());
18+
1719
@Before("execution(public * com.khoubyari.example.api.rest.*Controller.*(..))")
1820
public void logBeforeRestCall(JoinPoint pjp) throws Throwable {
19-
System.out.println(":::::AOP Before REST call:::::" + pjp);
21+
log.info(":::::AOP Before REST call:::::" + pjp);
2022
}
2123
}

src/main/java/com/khoubyari/example/api/rest/HotelController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.khoubyari.example.api.rest;
22

3+
import io.swagger.annotations.Api;
4+
import io.swagger.annotations.ApiOperation;
5+
import io.swagger.annotations.ApiParam;
6+
37
import com.khoubyari.example.domain.Hotel;
48
import com.khoubyari.example.exception.DataFormatException;
59
import com.khoubyari.example.service.HotelService;
6-
import com.wordnik.swagger.annotations.Api;
7-
import com.wordnik.swagger.annotations.ApiOperation;
8-
import com.wordnik.swagger.annotations.ApiParam;
10+
911
import org.springframework.beans.factory.annotation.Autowired;
1012
import org.springframework.data.domain.Page;
1113
import org.springframework.http.HttpStatus;
@@ -20,7 +22,7 @@
2022

2123
@RestController
2224
@RequestMapping(value = "/example/v1/hotels")
23-
@Api(value = "hotels", description = "Hotel API")
25+
@Api(tags = {"hotels"})
2426
public class HotelController extends AbstractRestHandler {
2527

2628
@Autowired

0 commit comments

Comments
 (0)