Skip to content

Commit b5dde9b

Browse files
lor6pivovarit
authored andcommitted
move custom port code, upgrade to boot 2 (eugenp#4126)
1 parent e725c02 commit b5dde9b

13 files changed

Lines changed: 80 additions & 21 deletions

File tree

‎spring-rest/pom.xml‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
<packaging>war</packaging>
99

1010
<parent>
11-
<artifactId>parent-boot-5</artifactId>
12-
<groupId>com.baeldung</groupId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<relativePath>../parent-boot-5</relativePath>
11+
<artifactId>spring-boot-starter-parent</artifactId>
12+
<groupId>org.springframework.boot</groupId>
13+
<version>2.0.1.RELEASE</version>
1514
</parent>
1615

1716
<dependencies>
1817

1918
<!-- Spring Boot Dependencies -->
2019

20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
</dependency>
2124
<dependency>
2225
<groupId>org.springframework.boot</groupId>
2326
<artifactId>spring-boot-starter-thymeleaf</artifactId>
@@ -32,7 +35,7 @@
3235
</dependency>
3336
<dependency>
3437
<groupId>org.springframework.boot</groupId>
35-
<artifactId>spring-boot-test</artifactId>
38+
<artifactId>spring-boot-starter-test</artifactId>
3639
</dependency>
3740

3841
<!-- Spring -->
@@ -175,6 +178,12 @@
175178
<artifactId>pact-jvm-provider-junit_2.11</artifactId>
176179
<version>${pact.version}</version>
177180
</dependency>
181+
182+
<dependency>
183+
<groupId>io.rest-assured</groupId>
184+
<artifactId>rest-assured</artifactId>
185+
<version>${rest-assured.version}</version>
186+
</dependency>
178187

179188
</dependencies>
180189

@@ -235,7 +244,20 @@
235244
</execution>
236245
</executions>
237246
</plugin>
238-
247+
<plugin>
248+
<groupId>org.apache.maven.plugins</groupId>
249+
<artifactId>maven-surefire-plugin</artifactId>
250+
<configuration>
251+
<forkCount>3</forkCount>
252+
<reuseForks>true</reuseForks>
253+
<excludes>
254+
<exclude>**/*IntegrationTest.java</exclude>
255+
<exclude>**/*LongRunningUnitTest.java</exclude>
256+
<exclude>**/*ManualTest.java</exclude>
257+
<exclude>**/*LiveTest.java</exclude>
258+
</excludes>
259+
</configuration>
260+
</plugin>
239261
</plugins>
240262

241263
</build>
@@ -331,6 +353,7 @@
331353
<json.path.version>2.2.0</json.path.version>
332354

333355
<pact.version>3.5.11</pact.version>
356+
<rest-assured.version>3.1.0</rest-assured.version>
334357
</properties>
335358

336359
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.custom;
2+
3+
import java.util.Collections;
4+
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
8+
@SpringBootApplication
9+
public class CustomApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication app = new SpringApplication(CustomApplication.class);
13+
app.setDefaultProperties(Collections.singletonMap("server.port", "8083"));
14+
app.run(args);
15+
}
16+
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.custom;
2+
3+
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
4+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5+
import org.springframework.stereotype.Component;
6+
7+
//@Component
8+
public class ServerPortCustomizer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
9+
10+
@Override
11+
public void customize(ConfigurableWebServerFactory factory) {
12+
factory.setPort(8086);
13+
}
14+
15+
}

‎spring-rest/src/main/java/com/baeldung/web/log/app/Application.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
6-
import org.springframework.boot.web.support.SpringBootServletInitializer;
76
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
88

99
@EnableAutoConfiguration
1010
@ComponentScan("com.baeldung.web.log")

‎spring-rest/src/main/java/com/baeldung/web/log/controller/TaxiFareController.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77
import org.springframework.beans.factory.annotation.Autowired;
8-
import org.springframework.stereotype.Controller;
98
import org.springframework.web.bind.annotation.GetMapping;
109
import org.springframework.web.bind.annotation.PostMapping;
1110
import org.springframework.web.bind.annotation.RequestBody;
12-
import org.springframework.web.bind.annotation.ResponseBody;
1311

1412
import com.baeldung.web.log.data.RateCard;
1513
import com.baeldung.web.log.data.TaxiRide;

‎spring-rest/src/main/java/org/baeldung/config/MainApplication.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
55
import org.springframework.context.annotation.ComponentScan;
6-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
77

88
@EnableAutoConfiguration
99
@ComponentScan("org.baeldung")
10-
public class MainApplication extends WebMvcConfigurerAdapter {
10+
public class MainApplication implements WebMvcConfigurer {
1111

1212
public static void main(final String[] args) {
1313
SpringApplication.run(MainApplication.class, args);

‎spring-rest/src/main/java/org/baeldung/config/WebConfig.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import org.springframework.context.annotation.ComponentScan;
44
import org.springframework.context.annotation.Configuration;
55
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
6+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
77

88
/*
99
* Please note that main web configuration is in src/main/webapp/WEB-INF/api-servlet.xml
1010
*/
1111
@Configuration
1212
@EnableWebMvc
1313
@ComponentScan({ "org.baeldung.web" })
14-
public class WebConfig extends WebMvcConfigurerAdapter {
14+
public class WebConfig implements WebMvcConfigurer {
1515

1616
public WebConfig() {
1717
super();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
server.port= 8082
2-
server.context-path=/spring-rest
2+
server.servlet.context-path=/spring-rest

‎spring-rest/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
public class TestRestTemplateBasicLiveTest {
2121

22-
private RestTemplate restTemplate;
22+
private RestTemplateBuilder restTemplate;
2323
private static final String FOO_RESOURCE_URL = "http://localhost:" + APPLICATION_PORT + "/spring-rest/foos";
2424
private static final String URL_SECURED_BY_AUTHENTICATION = "http://httpbin.org/basic-auth/user/passwd";
2525
private static final String BASE_URL = "http://localhost:" + APPLICATION_PORT + "/spring-rest";
2626

2727
@Before
2828
public void beforeTest() {
29-
restTemplate = new RestTemplate();
29+
restTemplate = new RestTemplateBuilder();
3030
}
3131

3232
// GET

spring-rest/src/test/java/org/baeldung/pact/PactProviderTest.java renamed to spring-rest/src/test/java/org/baeldung/pact/PactProviderLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@RunWith(PactRunner.class)
1818
@Provider("test_provider")
1919
@PactFolder("pacts")
20-
public class PactProviderTest {
20+
public class PactProviderLiveTest {
2121

2222
@TestTarget
2323
public final Target target = new HttpTarget("http", "localhost", 8082, "/spring-rest");

0 commit comments

Comments
 (0)