move custom port code, upgrade to boot 2 (#4126)
This commit is contained in:
parent
e725c023df
commit
b5dde9b233
|
@ -8,16 +8,19 @@
|
|||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-5</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-5</relativePath>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<version>2.0.1.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring Boot Dependencies -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
|
@ -32,7 +35,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring -->
|
||||
|
@ -176,6 +179,12 @@
|
|||
<version>${pact.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>${rest-assured.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -235,7 +244,20 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
@ -331,6 +353,7 @@
|
|||
<json.path.version>2.2.0</json.path.version>
|
||||
|
||||
<pact.version>3.5.11</pact.version>
|
||||
<rest-assured.version>3.1.0</rest-assured.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.custom;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CustomApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(CustomApplication.class);
|
||||
app.setDefaultProperties(Collections.singletonMap("server.port", "8083"));
|
||||
app.run(args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.custom;
|
||||
|
||||
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
//@Component
|
||||
public class ServerPortCustomizer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableWebServerFactory factory) {
|
||||
factory.setPort(8086);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,8 +3,8 @@ package com.baeldung.web.log.app;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("com.baeldung.web.log")
|
||||
|
|
|
@ -5,11 +5,9 @@ import javax.validation.Valid;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.baeldung.web.log.data.RateCard;
|
||||
import com.baeldung.web.log.data.TaxiRide;
|
||||
|
|
|
@ -3,11 +3,11 @@ package org.baeldung.config;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("org.baeldung")
|
||||
public class MainApplication extends WebMvcConfigurerAdapter {
|
||||
public class MainApplication implements WebMvcConfigurer {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(MainApplication.class, args);
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.baeldung.config;
|
|||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/*
|
||||
* Please note that main web configuration is in src/main/webapp/WEB-INF/api-servlet.xml
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
|||
@Configuration
|
||||
@EnableWebMvc
|
||||
@ComponentScan({ "org.baeldung.web" })
|
||||
public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
public WebConfig() {
|
||||
super();
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
server.port= 8082
|
||||
server.context-path=/spring-rest
|
||||
server.servlet.context-path=/spring-rest
|
|
@ -19,14 +19,14 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
public class TestRestTemplateBasicLiveTest {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private RestTemplateBuilder restTemplate;
|
||||
private static final String FOO_RESOURCE_URL = "http://localhost:" + APPLICATION_PORT + "/spring-rest/foos";
|
||||
private static final String URL_SECURED_BY_AUTHENTICATION = "http://httpbin.org/basic-auth/user/passwd";
|
||||
private static final String BASE_URL = "http://localhost:" + APPLICATION_PORT + "/spring-rest";
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
restTemplate = new RestTemplate();
|
||||
restTemplate = new RestTemplateBuilder();
|
||||
}
|
||||
|
||||
// GET
|
||||
|
|
|
@ -17,7 +17,7 @@ import au.com.dius.pact.provider.junit.target.TestTarget;
|
|||
@RunWith(PactRunner.class)
|
||||
@Provider("test_provider")
|
||||
@PactFolder("pacts")
|
||||
public class PactProviderTest {
|
||||
public class PactProviderLiveTest {
|
||||
|
||||
@TestTarget
|
||||
public final Target target = new HttpTarget("http", "localhost", 8082, "/spring-rest");
|
|
@ -8,7 +8,7 @@ Content-Length: 1759
|
|||
Connection: keep-alive
|
||||
Accept-Ranges: bytes
|
||||
Server: nginx/1.10.0 (Ubuntu)
|
||||
Date: Fri, 23 Jun 2017 15:44:52 GMT
|
||||
Date: Sat, 28 Apr 2018 20:53:35 GMT
|
||||
Last-Modified: Tue, 27 May 2014 02:35:47 GMT
|
||||
ETag: "5383fa03-6df"
|
||||
OkHttp-Sent-Millis: 1489054646765
|
||||
|
|
|
@ -4,10 +4,10 @@ GET
|
|||
HTTP/1.1 301 Moved Permanently
|
||||
8
|
||||
Server: nginx/1.10.0 (Ubuntu)
|
||||
Date: Sat, 24 Jun 2017 01:06:43 GMT
|
||||
Date: Sat, 28 Apr 2018 20:53:33 GMT
|
||||
Content-Type: text/html
|
||||
Content-Length: 194
|
||||
Connection: keep-alive
|
||||
Location: https://publicobject.com/helloworld.txt
|
||||
OkHttp-Sent-Millis: 1498266403462
|
||||
OkHttp-Received-Millis: 1498266403727
|
||||
OkHttp-Sent-Millis: 1524948815122
|
||||
OkHttp-Received-Millis: 1524948815342
|
||||
|
|
|
@ -61,3 +61,9 @@ READ 2d9345a30d2cc31bb3091d70a8ef6c18
|
|||
READ 4b217e04ba52215f3a6b64d28f6729c6
|
||||
DIRTY 4b217e04ba52215f3a6b64d28f6729c6
|
||||
CLEAN 4b217e04ba52215f3a6b64d28f6729c6 333 194
|
||||
READ 4b217e04ba52215f3a6b64d28f6729c6
|
||||
DIRTY 4b217e04ba52215f3a6b64d28f6729c6
|
||||
CLEAN 4b217e04ba52215f3a6b64d28f6729c6 333 194
|
||||
READ 2d9345a30d2cc31bb3091d70a8ef6c18
|
||||
DIRTY 2d9345a30d2cc31bb3091d70a8ef6c18
|
||||
CLEAN 2d9345a30d2cc31bb3091d70a8ef6c18 7618 1759
|
||||
|
|
Loading…
Reference in New Issue