Let's get started.
First, create a new Maven project. In the pom.xml file, include the following dependencies: spring-boot-starter-web, spring-boot-starter-test, and junit.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
@RestController
@RequestMapping("/api")
public class BotEntryPointController {
@GetMapping("/alive")
public String alive() {
return "alive";
}
}
@SpringBootApplication
public class NiceBotApplication {
public static void main(String[] args) {
SpringApplication.run(NiceBotApplication.class, args);
}
}
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
public class BotEntryPointControllerTest {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void aliveTest() {
ResponseEntity<String> response = restTemplate.getForEntity("/api/alive", String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals("alive", response.getBody());
}
}
mvn clean package -DskipTests -Pprod
mvn clean install -DskipTests=true -Dapp.env=prod
<build>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>example-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<environment>${app.env}</environment>
</configuration>
</plugin>
</plugins>
</build>
mvn clean install -Pprod
<profiles>
<profile>
<id>dev</id>
<properties>
<app.env>dev</app.env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<app.env>prod</app.env>
</properties>
</profile>
</profiles>